Class: TmxParser::Variant

Inherits:
Object
  • Object
show all
Defined in:
lib/tmx-parser/elements.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale) ⇒ Variant

Returns a new instance of Variant.



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

def initialize(locale)
  @locale = locale
  @elements = []
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



58
59
60
# File 'lib/tmx-parser/elements.rb', line 58

def elements
  @elements
end

#localeObject (readonly)

Returns the value of attribute locale.



57
58
59
# File 'lib/tmx-parser/elements.rb', line 57

def locale
  @locale
end

Instance Method Details

#==(other_variant) ⇒ Object



79
80
81
82
83
84
# File 'lib/tmx-parser/elements.rb', line 79

def ==(other_variant)
  locale == locale &&
    elements.each_with_index.all? do |element, idx|
      other_variant.elements[idx] == element
    end
end

#copyObject



69
70
71
72
73
74
75
76
77
# File 'lib/tmx-parser/elements.rb', line 69

def copy
  self.class.new(locale.dup).tap do |new_variant|
    new_variant.elements.concat(
      elements.map do |element|
        element.respond_to?(:copy) ? element.copy : element.dup
      end
    )
  end
end

#receive_text(str) ⇒ Object



65
66
67
# File 'lib/tmx-parser/elements.rb', line 65

def receive_text(str)
  @elements << str
end