Class: TmxParser::Unit

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tuid, segtype) ⇒ Unit

Returns a new instance of Unit.



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

def initialize(tuid, segtype)
  @tuid = tuid
  @segtype = segtype
  @properties = {}
  @variants = []
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



6
7
8
# File 'lib/tmx-parser/elements.rb', line 6

def properties
  @properties
end

#segtypeObject (readonly)

Returns the value of attribute segtype.



6
7
8
# File 'lib/tmx-parser/elements.rb', line 6

def segtype
  @segtype
end

#tuidObject (readonly)

Returns the value of attribute tuid.



6
7
8
# File 'lib/tmx-parser/elements.rb', line 6

def tuid
  @tuid
end

#variantsObject (readonly)

Returns the value of attribute variants.



6
7
8
# File 'lib/tmx-parser/elements.rb', line 6

def variants
  @variants
end

Instance Method Details

#==(other_unit) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/tmx-parser/elements.rb', line 24

def ==(other_unit)
  tuid == other_unit.tuid &&
    segtype == other_unit.segtype &&
    variants.each_with_index.all? do |v, idx|
      other_unit.variants[idx] == v
    end &&
    properties.each_with_index.all? do |(key, prop_val), idx|
      other_unit.properties[key] == prop_val
    end
end

#copyObject



15
16
17
18
19
20
21
22
# File 'lib/tmx-parser/elements.rb', line 15

def copy
  self.class.new(tuid.dup, segtype.dup).tap do |new_unit|
    new_unit.variants.concat(variants.map(&:copy))
    properties.each do |key, property_value|
      new_unit.properties[key] = property_value.copy
    end
  end
end