Class: Localite::Backend::Tr

Inherits:
Object
  • Object
show all
Defined in:
lib/localite/tr.rb

Defined Under Namespace

Modules: Etest Classes: IO

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, name = nil) ⇒ Tr

Returns a new instance of Tr.



42
43
44
# File 'lib/localite/tr.rb', line 42

def initialize(src, name=nil)
  @src, @name = src, name
end

Instance Attribute Details

#indentObject (readonly)

Returns the value of attribute indent.



46
47
48
# File 'lib/localite/tr.rb', line 46

def indent
  @indent
end

#nameObject (readonly)

Returns the value of attribute name.



46
47
48
# File 'lib/localite/tr.rb', line 46

def name
  @name
end

Class Method Details

.load(file, &block) ⇒ Object



38
39
40
# File 'lib/localite/tr.rb', line 38

def self.load(file, &block)
  new(File.open(file), file).parse(&block)
end

.parse(io, name = nil, &block) ⇒ Object



34
35
36
# File 'lib/localite/tr.rb', line 34

def self.parse(io, name=nil, &block)
  new(io, name).parse(&block)
end

Instance Method Details

#keysObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/localite/tr.rb', line 48

def keys
  return @keys if @keys

  if @parse
    @keys = @parse.keys
  else
    @keys = []
    parse_ do |k,_|
      @keys << k
    end
    @keys.uniq!
  end

  @keys.sort!
end

#parse(&block) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/localite/tr.rb', line 64

def parse(&block)
  if block_given?
    parse_(&block)
  else
    @parse ||= begin
      hash = {}
      parse_ do |k,v|
        duplicate_entry(k) if hash.key?(k)
        hash[k] = v
      end
      hash
    end
  end
end