SNN (Style Name Notation) implementation for the Ruby language.
SNN (Style Name Notation) is a formal, rule-agnostic naming system for identifying styles in abstract strategy board games such as chess, shōgi, xiangqi, and their many variants. Each style is represented by a canonical, human-readable ASCII name (e.g., "Chess"
, "Shogi"
, "Xiangqi"
, "Minishogi"
).
This gem implements the SNN Specification v1.0.0, supporting validation, parsing, and comparison of style names.
# In your Gemfile
gem "sashite-snn"
Or install manually:
gem install sashite-snn
require "sashite/snn"
# Parse SNN strings into style name objects
name = Sashite::Snn.parse("Shogi") # => #<Snn::Name value="Shogi">
name.to_s # => "Shogi"
name.value # => "Shogi"
# Create from string or symbol
name = Sashite::Snn.name("Chess") # => #<Snn::Name value="Chess">
name = Sashite::Snn::Name.new(:Xiangqi) # => #<Snn::Name value="Xiangqi">
# Validate SNN strings
Sashite::Snn.valid?("Go9x9") # => true
Sashite::Snn.valid?("chess") # => false (must start with uppercase)
Sashite::Snn.valid?("3DChess") # => false (invalid character)
a = Sashite::Snn.parse("Chess960")
b = Sashite::Snn.parse("Chess960")
a == b # => true
a.same_base_name?(Sashite::Snn.parse("Chess")) # => true if both resolve to same SIN
a.to_s # => "Chess960"
# All names are normalized to a canonical format
name = Sashite::Snn.parse("Minishogi")
name.value # => "Minishogi"
name.to_s # => "Minishogi"
names = %w[Chess Shogi Makruk Antichess Minishogi].map { |n| Sashite::Snn.parse(n) }
# Filter by prefix
names.select { |n| n.value.start_with?("Mini") }.map(&:to_s)
# => ["Minishogi"]
<uppercase-letter>[<lowercase-letter | digit>]*
<snn> ::= <uppercase-letter> <tail>
<tail> ::= "" ; Single letter (e.g., "X")
| <alphanumeric-char> <tail> ; Extended name
<alphanumeric-char> ::= <lowercase-letter> | <digit>
<uppercase-letter> ::= "A" | "B" | "C" | ... | "Z"
<lowercase-letter> ::= "a" | "b" | "c" | ... | "z"
<digit> ::= "0" | "1" | "2" | "3" | ... | "9"
/\A[A-Z][a-z0-9]*\z/
- Human-readable: Names like
"Shogi"
or"Chess960"
are intuitive and descriptive. - Canonical: One valid name per game style within a given context.
- ASCII-only: Compatible with all systems.
- Scalable: Supports unlimited distinct names for current and future game variants.
SNN names serve as the formal source for SIN character identifiers. For example:
SNN | SIN |
---|---|
Chess |
C /c |
Shogi |
S /s |
Xiangqi |
X /x |
Makruk |
M /m |
Multiple SNN names may map to the same SIN character (e.g., "Chess"
and "Chess960"
both → C
), but SNN provides unambiguous naming within broader contexts.
Sashite::Snn.parse("Chess") # => #<Snn::Name value="Chess">
Sashite::Snn.parse("Chess960") # => #<Snn::Name value="Chess960">
Sashite::Snn.valid?("Minishogi") # => true
Sashite::Snn.valid?("miniShogi") # => false
Sashite::Snn.valid?(str)
– Returnstrue
if the string is valid SNN.Sashite::Snn.parse(str)
– Returns aSashite::Snn::Name
object.Sashite::Snn.name(sym_or_str)
– Alias for constructing a name.
#value
– Returns the canonical string value.#to_s
– Returns the string representation.#==
,#eql?
,#hash
– Value-based equality.#same_base_name?(other)
– Optional helper for SIN mapping equivalence.
# Clone the repository
git clone https://github.com/sashite/snn.rb.git
cd snn.rb
# Install dependencies
bundle install
# Run tests
ruby test.rb
# Generate documentation
yard doc
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature
) - Add tests for your changes
- Ensure all tests pass (
ruby test.rb
) - Commit your changes (
git commit -am 'Add new feature'
) - Push to the branch (
git push origin feature/new-feature
) - Create a Pull Request
Available as open source under the MIT License.
Maintained by Sashité — promoting chess variants and sharing the beauty of board game cultures.