Class: JSGF::Atom

Inherits:
Object
  • Object
show all
Defined in:
lib/jsgf/atom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atom, *tags, weight: nil) ⇒ Atom

Returns a new instance of Atom.

Parameters:

  • atom (String)

    the atom of the JSGF::Atom

  • weight (Number) (defaults to: nil)

    the weight to be used when part of an JSGF::Alternation. Valid values are 0..1.0.

  • tags (Array)

    any tags to be stored with the JSGF::Atom



18
19
20
21
22
# File 'lib/jsgf/atom.rb', line 18

def initialize(atom, *tags, weight:nil)
    @atom = atom
    @tags = tags
    @weight = (weight && (weight != 1.0)) ? weight : nil
end

Instance Attribute Details

#atomString

Returns the atom of the JSGF::Atom.

Returns:



5
6
7
# File 'lib/jsgf/atom.rb', line 5

def atom
  @atom
end

#tagsArray

Returns the collection of tags to be stored with the JSGF::Atom.

Returns:

  • (Array)

    the collection of tags to be stored with the JSGF::Atom



13
14
15
# File 'lib/jsgf/atom.rb', line 13

def tags
  @tags
end

#weightNumber

Returns the JSGF::Atom‘s weight, when part of an JSGF::Alternation. Defaults to 1.0.

Returns:



9
10
11
# File 'lib/jsgf/atom.rb', line 9

def weight
  @weight
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


24
25
26
# File 'lib/jsgf/atom.rb', line 24

def eql?(other)
    @atom.eql?(other.atom) && @tags.eql?(other.tags) && @weight.eql?(other.weight)
end

#to_sObject

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, *tags].compact.join(' ')
end