Class: JSGF::Atom
- Inherits:
-
Object
- Object
- JSGF::Atom
- Defined in:
- lib/jsgf/atom.rb
Instance Attribute Summary collapse
-
#atom ⇒ String
The atom of the Atom.
-
#tags ⇒ Array
The collection of tags to be stored with the Atom.
-
#weight ⇒ Number
The Atom‘s weight, when part of an Alternation.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(atom, *tags, weight: nil) ⇒ Atom
constructor
A new instance of Atom.
-
#to_s ⇒ Object
Stringify in a manner suitable for output to a JSGF file.
Constructor Details
#initialize(atom, *tags, weight: nil) ⇒ Atom
Returns a new instance of Atom.
18 19 20 21 22 |
# File 'lib/jsgf/atom.rb', line 18 def initialize(atom, *, weight:nil) @atom = atom @tags = @weight = (weight && (weight != 1.0)) ? weight : nil end |
Instance Attribute Details
#atom ⇒ String
Returns the atom of the JSGF::Atom.
5 6 7 |
# File 'lib/jsgf/atom.rb', line 5 def atom @atom end |
#tags ⇒ Array
Returns the collection of tags to be stored with the JSGF::Atom.
13 14 15 |
# File 'lib/jsgf/atom.rb', line 13 def @tags end |
#weight ⇒ Number
Returns the JSGF::Atom‘s weight, when part of an JSGF::Alternation. Defaults to 1.0.
9 10 11 |
# File 'lib/jsgf/atom.rb', line 9 def weight @weight end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
24 25 26 |
# File 'lib/jsgf/atom.rb', line 24 def eql?(other) @atom.eql?(other.atom) && @tags.eql?(other.) && @weight.eql?(other.weight) end |
#to_s ⇒ Object
Stringify in a manner suitable for output to a JSGF file
30 31 32 |
# File 'lib/jsgf/atom.rb', line 30 def to_s [(weight && (weight != 1.0)) ? "/#{weight}/" : nil, atom, *].compact.join(' ') end |