SNN (Style Name Notation) implementation for Ruby.
This library implements the SNN Specification v1.0.0.
| Constraint | Value | Rationale |
|---|---|---|
| Max string length | 32 | Sufficient for realistic style names |
These constraints enable bounded memory usage and safe parsing.
# In your Gemfile
gem "sashite-snn"Or install manually:
gem install sashite-snnConvert an SNN string into a StyleName object.
require "sashite/snn"
# Standard parsing (raises on error)
snn = Sashite::Snn.parse("Chess")
snn.name # => "Chess"
# With numeric suffix
snn = Sashite::Snn.parse("Chess960")
snn.name # => "Chess960"
# Invalid input raises ArgumentError
Sashite::Snn.parse("chess") # => raises ArgumentError, "invalid format"
Sashite::Snn.parse("") # => raises ArgumentError, "empty input"Convert a StyleName back to an SNN string.
# From StyleName object
snn = Sashite::Snn::StyleName.new("Chess")
snn.to_s # => "Chess"
# String interpolation
"Playing #{snn}" # => "Playing Chess"# Boolean check
Sashite::Snn.valid?("Chess") # => true
Sashite::Snn.valid?("Chess960") # => true
Sashite::Snn.valid?("chess") # => false (lowercase start)
Sashite::Snn.valid?("") # => false (empty)snn = Sashite::Snn.parse("Chess960")
# Get the name (attribute)
snn.name # => "Chess960"# StyleName represents a validated SNN style name.
class Sashite::Snn::StyleName
# Creates a StyleName from a valid name string.
# Raises ArgumentError if the name is invalid.
#
# @param name [String] SNN style name
# @return [StyleName]
def initialize(name)
# Returns the style name.
#
# @return [String]
def name
# Returns the SNN string representation.
#
# @return [String]
def to_s
endSashite::Snn::StyleName::MAX_STRING_LENGTH # => 32# Parses an SNN string into a StyleName.
# Raises ArgumentError if the string is not valid.
#
# @param string [String] SNN style name string
# @return [StyleName]
# @raise [ArgumentError] if invalid
def Sashite::Snn.parse(string)# Reports whether string is a valid SNN style name.
#
# @param string [String] SNN style name string
# @return [Boolean]
def Sashite::Snn.valid?(string)All parsing and validation errors raise ArgumentError with descriptive messages:
| Message | Cause |
|---|---|
"empty input" |
String length is 0 |
"input too long" |
String exceeds 32 characters |
"invalid format" |
Does not match SNN format |
- Bounded values: Maximum string length prevents resource exhaustion
- Object-oriented:
StyleNameclass enables methods and encapsulation - Ruby idioms:
valid?predicate,to_sconversion,ArgumentErrorfor invalid input - Immutable style names:
freezeafter construction - No dependencies: Pure Ruby standard library only
- Game Protocol — Conceptual foundation
- SNN Specification — Official specification
- SNN Examples — Usage examples
Available as open source under the Apache License 2.0.