Class: Applyrics::StringsFile
- Inherits:
-
Object
- Object
- Applyrics::StringsFile
show all
- Defined in:
- lib/applyrics/stringsfile.rb
Defined Under Namespace
Classes: Generator, Parser
Instance Method Summary
collapse
Constructor Details
#initialize(path, data = nil) ⇒ StringsFile
Returns a new instance of StringsFile.
5
6
7
8
9
10
11
|
# File 'lib/applyrics/stringsfile.rb', line 5
def initialize(path, data=nil)
@path = path
@hash = data
if data.nil?
read
end
end
|
Instance Method Details
#have_key? ⇒ Boolean
17
18
19
|
# File 'lib/applyrics/stringsfile.rb', line 17
def have_key?
end
|
#keys ⇒ Object
13
14
15
|
# File 'lib/applyrics/stringsfile.rb', line 13
def keys
end
|
#read ⇒ Object
29
30
31
32
33
34
|
# File 'lib/applyrics/stringsfile.rb', line 29
def read
@hash = {}
parser = Parser.new(@hash)
File.open(@path, 'rb:bom|utf-16LE:utf-8') { |fd| parser.parse fd }
self
end
|
#string_for_key(key) ⇒ Object
21
22
23
|
# File 'lib/applyrics/stringsfile.rb', line 21
def string_for_key(key)
end
|
#to_hash ⇒ Object
25
26
27
|
# File 'lib/applyrics/stringsfile.rb', line 25
def to_hash
@hash
end
|
#write ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/applyrics/stringsfile.rb', line 36
def write
temp = Tempfile.new(File.basename(@path))
begin
gen = Generator.new(@hash)
gen.run { |line| temp.puts line }
FileUtils.mv(temp.path, @path)
ensure
temp.close
end
end
|