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, optional: nil, reference: 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



28
29
30
31
32
33
34
# File 'lib/jsgf/atom.rb', line 28

def initialize(atom, *tags, weight:nil, optional:nil, reference:nil)
    @atom = atom
    @optional = optional
    @reference = reference
    @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

#referenceBool Also known as: reference?

Returns The JSGF::Atom is a reference to a Rule.

Returns:



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

def reference
  @reference
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



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

def tags
  @tags
end

#weightNumber

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

Returns:



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

def weight
  @weight
end

Instance Method Details

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

Returns:

  • (Boolean)


36
37
38
# File 'lib/jsgf/atom.rb', line 36

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

#optionalObject Also known as: optional?



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

def optional
  @optional
end

#to_sObject

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, *tags].compact.join(' ')
    s = '[' + s + ']' if optional?
    s
end