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.
- #reference ⇒ Bool (also: #reference?)
-
#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, optional: nil, reference: nil) ⇒ Atom
constructor
A new instance of Atom.
- #optional ⇒ Object (also: #optional?)
-
#to_s ⇒ Object
Stringify in a manner suitable for output to a JSGF file.
Constructor Details
#initialize(atom, *tags, weight: nil, optional: nil, reference: nil) ⇒ Atom
Returns a new instance of Atom.
28 29 30 31 32 33 34 |
# File 'lib/jsgf/atom.rb', line 28 def initialize(atom, *, weight:nil, optional:nil, reference:nil) @atom = atom @optional = optional @reference = reference @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 |
#reference ⇒ Bool Also known as: reference?
Returns The JSGF::Atom is a reference to a Rule.
14 15 16 |
# File 'lib/jsgf/atom.rb', line 14 def reference @reference end |
#tags ⇒ Array
Returns the collection of tags to be stored with the JSGF::Atom.
23 24 25 |
# File 'lib/jsgf/atom.rb', line 23 def @tags end |
#weight ⇒ Number
Returns the JSGF::Atom‘s weight, when part of an JSGF::Alternation. Defaults to 1.0.
19 20 21 |
# File 'lib/jsgf/atom.rb', line 19 def weight @weight end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
36 37 38 |
# File 'lib/jsgf/atom.rb', line 36 def eql?(other) @atom.eql?(other.atom) && @tags.eql?(other.) && @weight.eql?(other.weight) end |
#optional ⇒ Object Also known as: optional?
9 10 11 |
# File 'lib/jsgf/atom.rb', line 9 def optional @optional end |
#to_s ⇒ Object
Stringify in a manner suitable for output to a JSGF file
42 43 44 45 46 |
# File 'lib/jsgf/atom.rb', line 42 def to_s s = [(weight && (weight != 1.0)) ? "/#{weight}/" : nil, reference? ? '<'+atom+'>' : atom, *].compact.join(' ') s = '[' + s + ']' if optional? s end |