Class: TmxParser::Listener

Inherits:
Object
  • Object
show all
Includes:
TagNames
Defined in:
lib/tmx-parser/listener.rb

Constant Summary

Constants included from TagNames

TagNames::BEGIN_PAIRED_TAG, TagNames::END_PAIRED_TAG, TagNames::PLACEHOLDER_TAG, TagNames::PROPERTY_TAG, TagNames::SEGMENT_TAG, TagNames::UNIT_TAG, TagNames::VARIANT_TAG

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Listener

Returns a new instance of Listener.



10
11
12
13
# File 'lib/tmx-parser/listener.rb', line 10

def initialize(&block)
  @stack = []
  @proc = block
end

Instance Attribute Details

#procObject (readonly)

Returns the value of attribute proc.



8
9
10
# File 'lib/tmx-parser/listener.rb', line 8

def proc
  @proc
end

#unitsObject (readonly)

Returns the value of attribute units.



8
9
10
# File 'lib/tmx-parser/listener.rb', line 8

def units
  @units
end

Instance Method Details

#begin_paired_tag(i) ⇒ Object



53
54
55
56
57
# File 'lib/tmx-parser/listener.rb', line 53

def begin_paired_tag(i)
  begin_pair = BeginPair.new(i)
  current_unit.variants.last.elements << begin_pair
  stack.push(begin_pair)
end

#done(tag_name) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/tmx-parser/listener.rb', line 37

def done(tag_name)
  if tag_name == UNIT_TAG
    proc.call(current_unit)
  else
    if tag_name_for(stack.last) == tag_name
      stack.pop
    end
  end
end

#end_paired_tag(i) ⇒ Object



59
60
61
62
63
# File 'lib/tmx-parser/listener.rb', line 59

def end_paired_tag(i)
  end_pair = EndPair.new(i)
  current_unit.variants.last.elements << end_pair
  stack.push(end_pair)
end

#placeholder(type) ⇒ Object



47
48
49
50
51
# File 'lib/tmx-parser/listener.rb', line 47

def placeholder(type)
  placeholder = Placeholder.new(type)
  current_unit.variants.last.elements << placeholder
  stack.push(placeholder)
end

#property(name) ⇒ Object



25
26
27
28
29
# File 'lib/tmx-parser/listener.rb', line 25

def property(name)
  val = PropertyValue.new
  current_unit.properties[name] = val
  stack.push(val)
end

#text(str) ⇒ Object



31
32
33
34
35
# File 'lib/tmx-parser/listener.rb', line 31

def text(str)
  if last = stack.last
    last.receive_text(str)
  end
end

#unit(tuid, segtype) ⇒ Object



15
16
17
# File 'lib/tmx-parser/listener.rb', line 15

def unit(tuid, segtype)
  @current_unit = Unit.new(tuid, segtype)
end

#variant(locale) ⇒ Object



19
20
21
22
23
# File 'lib/tmx-parser/listener.rb', line 19

def variant(locale)
  variant = Variant.new(locale)
  current_unit.variants << variant
  stack.push(variant)
end