Class: JSGF::Grammar
- Inherits:
-
Object
- Object
- JSGF::Grammar
- Defined in:
- lib/jsgf/grammar.rb
Instance Attribute Summary collapse
-
#character_encoding ⇒ Object
readonly
Returns the value of attribute character_encoding.
-
#grammar_name ⇒ Object
readonly
Returns the value of attribute grammar_name.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#private_rules ⇒ Object
readonly
Returns the value of attribute private_rules.
-
#public_rules ⇒ Object
readonly
Returns the value of attribute public_rules.
- #rules ⇒ Object
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(name: nil, character_encoding: nil, locale: nil, private_rules: {}, public_rules: {}, version: nil) ⇒ Grammar
constructor
A new instance of Grammar.
- #to_s ⇒ Object
Constructor Details
#initialize(name: nil, character_encoding: nil, locale: nil, private_rules: {}, public_rules: {}, version: nil) ⇒ Grammar
Returns a new instance of Grammar.
10 11 12 13 14 15 16 17 |
# File 'lib/jsgf/grammar.rb', line 10 def initialize(name:nil, character_encoding:nil, locale:nil, private_rules:{}, public_rules:{}, version:nil) @character_encoding = character_encoding @locale = locale @grammar_name = name @private_rules = private_rules @public_rules = public_rules @version = version end |
Instance Attribute Details
#character_encoding ⇒ Object (readonly)
Returns the value of attribute character_encoding.
3 4 5 |
# File 'lib/jsgf/grammar.rb', line 3 def character_encoding @character_encoding end |
#grammar_name ⇒ Object (readonly)
Returns the value of attribute grammar_name.
5 6 7 |
# File 'lib/jsgf/grammar.rb', line 5 def grammar_name @grammar_name end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
4 5 6 |
# File 'lib/jsgf/grammar.rb', line 4 def locale @locale end |
#private_rules ⇒ Object (readonly)
Returns the value of attribute private_rules.
6 7 8 |
# File 'lib/jsgf/grammar.rb', line 6 def private_rules @private_rules end |
#public_rules ⇒ Object (readonly)
Returns the value of attribute public_rules.
7 8 9 |
# File 'lib/jsgf/grammar.rb', line 7 def public_rules @public_rules end |
#rules ⇒ Object
21 22 23 |
# File 'lib/jsgf/grammar.rb', line 21 def rules @public_rules.merge(@private_rules) end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
8 9 10 |
# File 'lib/jsgf/grammar.rb', line 8 def version @version end |
Instance Method Details
#to_s ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/jsgf/grammar.rb', line 25 def to_s private_rule_array = @private_rules.map do |(name, rule)| atoms = rule.map {|a| unparse_atom(a) }.join(' ') "<#{name}> = #{atoms};" end public_rule_array = @public_rules.map do |(name, rule)| atoms = rule.map {|a| unparse_atom(a) }.join(' ') "public <#{name}> = #{atoms};" end [header, grammar_header, *public_rule_array, *private_rule_array].join("\n") end |