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.
-
#optional ⇒ Object
Returns the value of attribute optional.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Enumerable collapse
Instance Method Summary collapse
-
#initialize(*args) ⇒ Alternation
constructor
A new instance of Alternation.
- #push(*args) ⇒ Object
- #size ⇒ Object
- #weights ⇒ Object
Constructor Details
#initialize(*args) ⇒ Alternation
Returns a new instance of Alternation.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jsgf/alternation.rb', line 9 def initialize(*args) @elements = args.map do |a| case a when String case a when /\<(.*)\>/, /:(.*)/ then {name:$1, weight:1.0, tags:[]} else {atom:a, weight:1.0, tags:[]} end when Symbol then {name:a.to_s, weight:1.0, tags:[]} else a end end @optional = false = [] end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
5 6 7 |
# File 'lib/jsgf/alternation.rb', line 5 def elements @elements end |
#optional ⇒ Object
Returns the value of attribute optional.
6 7 8 |
# File 'lib/jsgf/alternation.rb', line 6 def optional @optional end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
7 8 9 |
# File 'lib/jsgf/alternation.rb', line 7 def end |
Instance Method Details
#each(*args, &block) ⇒ Object
29 30 31 |
# File 'lib/jsgf/alternation.rb', line 29 def each(*args, &block) elements.each(*args, &block) end |
#push(*args) ⇒ Object
34 35 36 |
# File 'lib/jsgf/alternation.rb', line 34 def push(*args) @elements.push *args end |
#size ⇒ Object
38 39 40 |
# File 'lib/jsgf/alternation.rb', line 38 def size @elements.size end |
#weights ⇒ Object
42 43 44 |
# File 'lib/jsgf/alternation.rb', line 42 def weights @elements.map {|a| a[:weight]} end |