Class: PoAndXliffConsolidator::TranslateUnit

Inherits:
Object
  • Object
show all
Includes:
Comparable, Logging
Defined in:
lib/po_and_xliff_consolidator/translate_unit.rb

Constant Summary collapse

@@priorities =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, logger, #logger, logger=

Constructor Details

#initialize(msgid, msgstr) ⇒ TranslateUnit

Returns a new instance of TranslateUnit.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 28

def initialize(msgid, msgstr)
  @msgid = chomp_all(msgid)
  @msgstr = chomp_all(msgstr)
  @msgid_downcase = TranslateUnit::msgid_key(msgid)
  @msgid_downcase_singular = @msgid_downcase.chomp('s')

  @@priorities.each_with_index do |string, index|
    if msgid_downcase.include? string
      @priority = index
      break
    end
    @priority = @@priorities.count
  end
end

Instance Attribute Details

#msgidObject

Returns the value of attribute msgid.



8
9
10
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 8

def msgid
  @msgid
end

#msgid_downcaseObject (readonly)

Returns the value of attribute msgid_downcase.



10
11
12
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 10

def msgid_downcase
  @msgid_downcase
end

#msgid_downcase_singularObject (readonly)

Returns the value of attribute msgid_downcase_singular.



11
12
13
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 11

def msgid_downcase_singular
  @msgid_downcase_singular
end

#msgstrObject (readonly)

Returns the value of attribute msgstr.



9
10
11
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 9

def msgstr
  @msgstr
end

#priorityObject (readonly)

Returns the value of attribute priority.



12
13
14
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 12

def priority
  @priority
end

Class Method Details

.msgid_key(msgid) ⇒ Object



43
44
45
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 43

def self.msgid_key(msgid)
  Transform::intelligent_chomp(msgid)[:str].downcase
end

Instance Method Details

#<=>(a_n_other) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 16

def <=>(a_n_other)
  return -1 if priority < a_n_other.priority
  return 1 if priority > a_n_other.priority
  return -1 if msgid_downcase_singular < a_n_other.msgid_downcase_singular
  return 1 if msgid_downcase_singular > a_n_other.msgid_downcase_singular
  msgid_downcase <=> a_n_other.msgid_downcase
end

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



47
48
49
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 47

def ==(other)
  self.class === other and msgid_downcase == other.msgid_downcase
end

#chomp_all(str) ⇒ Object



24
25
26
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 24

def chomp_all(str)
  str.strip.chomp.chomp(':').chomp('...').chomp('..').chomp('')
end

#hashObject



53
54
55
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 53

def hash
  msgid_downcase.hash
end

#inspectObject



57
58
59
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 57

def inspect
  @msgid
end

#to_sObject



61
62
63
# File 'lib/po_and_xliff_consolidator/translate_unit.rb', line 61

def to_s
  msgid
end