Class: Lokale::LString

Inherits:
Object
  • Object
show all
Defined in:
lib/lokale/model.rb,
lib/lokale/agent.rb,
lib/lokale/model.rb

Overview

Hashable

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, str, note, target) ⇒ LString

Returns a new instance of LString.



6
7
8
# File 'lib/lokale/model.rb', line 6

def initialize(key, str, note, target)
  @key = key; @str = str; @note = note; @target = target
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



4
5
6
# File 'lib/lokale/model.rb', line 4

def key
  @key
end

#noteObject

Returns the value of attribute note.



4
5
6
# File 'lib/lokale/model.rb', line 4

def note
  @note
end

#sourceObject

Returns the value of attribute source.



4
5
6
# File 'lib/lokale/model.rb', line 4

def source
  @source
end

#strObject

Returns the value of attribute str.



4
5
6
# File 'lib/lokale/model.rb', line 4

def str
  @str
end

#targetObject

Returns the value of attribute target.



4
5
6
# File 'lib/lokale/model.rb', line 4

def target
  @target
end

Class Method Details

.from_xliff_string(s, lang) ⇒ Object



69
70
71
72
73
# File 'lib/lokale/agent.rb', line 69

def self.from_xliff_string(s, lang)
  str = LString.new(s.id, s.target, s.note, lang)
  str.source = s.source
  str
end

.strings_from_file(file_path, lang) ⇒ Object



10
11
12
13
# File 'lib/lokale/model.rb', line 10

def self.strings_from_file(file_path, lang)
  regex = /(?:\/\* (.+) \*\/.*\n)?"(.+)" *= *"(.+)";/
  File.read(file_path).scan(regex).map { |m| LString.new(m[1], m[2], m[0], lang) }
end

Instance Method Details

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



123
124
125
# File 'lib/lokale/model.rb', line 123

def ==(other)
	self.class === other && other.fields == fields
end

#fieldsObject



119
120
121
# File 'lib/lokale/model.rb', line 119

def fields
	[@key, @str, @note, @target]
end

#for_export(lang) ⇒ Object



75
76
77
78
79
# File 'lib/lokale/agent.rb', line 75

def for_export(lang)
  str = LString.new(@key, nil, @note, lang)
  str.source = @str
  str
end

#hashObject



129
130
131
# File 'lib/lokale/model.rb', line 129

def hash
	fields.hash
end

#inspectObject



15
16
17
# File 'lib/lokale/model.rb', line 15

def inspect
	"<\#LS:#{@key}; s:#{@str}; n:#{@note}; t:#{@target}>"
end

#prettyObject



65
66
67
# File 'lib/lokale/agent.rb', line 65

def pretty
  "\"#{key}\" = \"#{str}\";"
end

#write_formatObject



57
58
59
60
61
62
63
# File 'lib/lokale/agent.rb', line 57

def write_format
  note = @note unless @note.empty?
  note = @source if note.nil?
  note = "(no comment)" if note.nil?

  "/* #{note} */\n\"#{key}\" = \"#{str}\";\n"
end