Class: JSGF::Alternation
- Inherits:
-
Object
- Object
- JSGF::Alternation
- Includes:
- Enumerable
- Defined in:
- lib/jsgf/alternation.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Enumerable collapse
Attributes collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Alternation
constructor
A new instance of Alternation.
- #optional ⇒ Object (also: #optional?)
- #push(*args) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Alternation
Returns a new instance of Alternation.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jsgf/alternation.rb', line 16 def initialize(*args) @elements = args.map do |a| case a when String then Rule.parse_atom(a) when Symbol then JSGF::Atom.new(a.to_s, reference:true) else a end end @optional = false @tags = [] end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
7 8 9 |
# File 'lib/jsgf/alternation.rb', line 7 def elements @elements end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
14 15 16 |
# File 'lib/jsgf/alternation.rb', line 14 def @tags end |
Instance Method Details
#each(*args, &block) ⇒ Object
31 32 33 |
# File 'lib/jsgf/alternation.rb', line 31 def each(*args, &block) elements.each(*args, &block) end |
#optional ⇒ Object Also known as: optional?
11 12 13 |
# File 'lib/jsgf/alternation.rb', line 11 def optional @optional end |
#push(*args) ⇒ Object
36 37 38 |
# File 'lib/jsgf/alternation.rb', line 36 def push(*args) @elements.push *args end |
#size ⇒ Object
41 42 43 |
# File 'lib/jsgf/alternation.rb', line 41 def size @elements.size end |
#weights ⇒ Object
45 46 47 |
# File 'lib/jsgf/alternation.rb', line 45 def weights @elements.map {|a| a.respond_to?(:weight) ? a.weight : a[:weight]} end |