Class: JSGF::Alternation

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/jsgf/alternation.rb

Instance Attribute Summary collapse

Enumerable collapse

Attributes collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Alternation

Returns a new instance of Alternation.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jsgf/alternation.rb', line 16

def initialize(*args)
    @elements = args.map do |a|
	case a
	    when String then Rule.parse_atom(a)
	    when Symbol then JSGF::Atom.new(a.to_s, reference:true)
	    else
		a
	end
    end

    @optional = false
    @tags = []
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



7
8
9
# File 'lib/jsgf/alternation.rb', line 7

def elements
  @elements
end

#tagsObject (readonly)

Returns the value of attribute tags.



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

def tags
  @tags
end

Instance Method Details

#each(*args, &block) ⇒ Object



31
32
33
# File 'lib/jsgf/alternation.rb', line 31

def each(*args, &block)
    elements.each(*args, &block)
end

#optionalObject Also known as: optional?



11
12
13
# File 'lib/jsgf/alternation.rb', line 11

def optional
  @optional
end

#push(*args) ⇒ Object



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

def push(*args)
    @elements.push *args
end

#sizeObject



41
42
43
# File 'lib/jsgf/alternation.rb', line 41

def size
    @elements.size
end

#weightsObject



45
46
47
# File 'lib/jsgf/alternation.rb', line 45

def weights
    @elements.map {|a| a.respond_to?(:weight) ? a.weight : a[:weight]}
end