Class: GetPomo::Translation

Inherits:
Object
  • Object
show all
Defined in:
lib/get_pomo/translation.rb

Constant Summary collapse

FUZZY_REGEX =
/fuzzy\n$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



4
5
6
# File 'lib/get_pomo/translation.rb', line 4

def comment
  @comment
end

#msgidObject

Returns the value of attribute msgid.



4
5
6
# File 'lib/get_pomo/translation.rb', line 4

def msgid
  @msgid
end

#msgstrObject

Returns the value of attribute msgstr.



4
5
6
# File 'lib/get_pomo/translation.rb', line 4

def msgstr
  @msgstr
end

Instance Method Details

#add_text(text, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/get_pomo/translation.rb', line 6

def add_text(text,options)
  to = options[:to]
  if to.to_sym == :msgid_plural
    self.msgid = [msgid] unless msgid.is_a? Array
    msgid[1] = msgid[1].to_s + text
  elsif to.to_s =~ /^msgstr\[(\d)\]$/
    self.msgstr ||= []
    msgstr[$1.to_i] = msgstr[$1.to_i].to_s + text
  else
    #simple form
    send("#{to}=",send(to).to_s+text)
  end
end

#complete?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/get_pomo/translation.rb', line 24

def complete?
  not msgid.nil? and not msgstr.nil?
end

#fuzzy=(value) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/get_pomo/translation.rb', line 32

def fuzzy=(value)
  if value and not fuzzy?
    add_text "\nfuzzy", :to=>:comment
  else
    self.comment = comment.to_s.split(/$/).reject{|line|line=~FUZZY_REGEX}.join("\n")
  end
end

#fuzzy?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/get_pomo/translation.rb', line 28

def fuzzy?
  comment =~ FUZZY_REGEX
end

#plural?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/get_pomo/translation.rb', line 40

def plural?
  msgid.is_a? Array or msgstr.is_a? Array
end

#to_hashObject



20
21
22
# File 'lib/get_pomo/translation.rb', line 20

def to_hash
  {:msgid=>msgid,:msgstr=>msgstr,:comment=>comment}.reject{|k,value|value.nil?}
end