Class: Applyrics::StringsFile

Inherits:
Object
  • Object
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

Returns:

  • (Boolean)


17
18
19
# File 'lib/applyrics/stringsfile.rb', line 17

def have_key?
  # Not implemented...
end

#keysObject



13
14
15
# File 'lib/applyrics/stringsfile.rb', line 13

def keys
  # Not implemented...
end

#readObject



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)
  # Not implemented...
end

#to_hashObject



25
26
27
# File 'lib/applyrics/stringsfile.rb', line 25

def to_hash
  @hash
end

#writeObject



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