Class: Lokale::LString
- Inherits:
-
Object
- Object
- Lokale::LString
- Defined in:
- lib/lokale/model.rb,
lib/lokale/agent.rb,
lib/lokale/model.rb
Overview
Hashable
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#note ⇒ Object
Returns the value of attribute note.
-
#source ⇒ Object
Returns the value of attribute source.
-
#str ⇒ Object
Returns the value of attribute str.
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #fields ⇒ Object
- #for_export(lang) ⇒ Object
- #hash ⇒ Object
-
#initialize(key, str, note, target) ⇒ LString
constructor
A new instance of LString.
- #inspect ⇒ Object
- #pretty ⇒ Object
- #write_format ⇒ Object
Constructor Details
#initialize(key, str, note, target) ⇒ LString
Returns a new instance of LString.
20 21 22 |
# File 'lib/lokale/model.rb', line 20 def initialize(key, str, note, target) @key = key; @str = str; @note = note; @target = target end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
18 19 20 |
# File 'lib/lokale/model.rb', line 18 def key @key end |
#note ⇒ Object
Returns the value of attribute note.
18 19 20 |
# File 'lib/lokale/model.rb', line 18 def note @note end |
#source ⇒ Object
Returns the value of attribute source.
48 49 50 |
# File 'lib/lokale/agent.rb', line 48 def source @source end |
#str ⇒ Object
Returns the value of attribute str.
18 19 20 |
# File 'lib/lokale/model.rb', line 18 def str @str end |
#target ⇒ Object
Returns the value of attribute target.
18 19 20 |
# File 'lib/lokale/model.rb', line 18 def target @target end |
Class Method Details
.from_xliff_string(s, lang) ⇒ Object
40 41 42 43 44 |
# File 'lib/lokale/agent.rb', line 40 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
24 25 26 27 |
# File 'lib/lokale/model.rb', line 24 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?
131 132 133 |
# File 'lib/lokale/model.rb', line 131 def ==(other) self.class === other && other.fields == fields end |
#fields ⇒ Object
127 128 129 |
# File 'lib/lokale/model.rb', line 127 def fields [@key, @str, @note, @target] end |
#for_export(lang) ⇒ Object
50 51 52 53 54 |
# File 'lib/lokale/agent.rb', line 50 def for_export(lang) str = LString.new(@key, nil, @note, lang) str.source = @str str end |
#hash ⇒ Object
137 138 139 |
# File 'lib/lokale/model.rb', line 137 def hash fields.hash end |
#inspect ⇒ Object
29 30 31 |
# File 'lib/lokale/model.rb', line 29 def inspect "<\#LS:#{@key}; s:#{@str}; n:#{@note}; t:#{@target}>" end |
#pretty ⇒ Object
36 37 38 |
# File 'lib/lokale/agent.rb', line 36 def pretty "\"#{key}\" = \"#{str}\";" end |
#write_format ⇒ Object
31 32 33 34 |
# File 'lib/lokale/agent.rb', line 31 def write_format note = @note || "(no comment)" "/* #{note} */\n\"#{key}\" = \"#{str}\";\n" end |