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.



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

#keyObject

Returns the value of attribute key.



18
19
20
# File 'lib/lokale/model.rb', line 18

def key
  @key
end

#noteObject

Returns the value of attribute note.



18
19
20
# File 'lib/lokale/model.rb', line 18

def note
  @note
end

#sourceObject

Returns the value of attribute source.



38
39
40
# File 'lib/lokale/agent.rb', line 38

def source
  @source
end

#strObject

Returns the value of attribute str.



18
19
20
# File 'lib/lokale/model.rb', line 18

def str
  @str
end

#targetObject

Returns the value of attribute target.



18
19
20
# File 'lib/lokale/model.rb', line 18

def target
  @target
end

Class Method Details

.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?



127
128
129
# File 'lib/lokale/model.rb', line 127

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

#fieldsObject



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

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

#for_export(lang) ⇒ Object



40
41
42
43
44
# File 'lib/lokale/agent.rb', line 40

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

#hashObject



133
134
135
# File 'lib/lokale/model.rb', line 133

def hash
	fields.hash
end

#inspectObject



29
30
31
# File 'lib/lokale/model.rb', line 29

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

#prettyObject



34
35
36
# File 'lib/lokale/agent.rb', line 34

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

#write_formatObject



30
31
32
# File 'lib/lokale/agent.rb', line 30

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