Class: I18n::Index::Simple::Data

Inherits:
Hash show all
Defined in:
lib/i18n/index/simple/data.rb

Instance Attribute Summary

Attributes inherited from Hash

#to_yaml_style

Instance Method Summary collapse

Methods inherited from Hash

#delete_nested_if, #each_nested, #select_nested, #set_yaml_style, #slice, #slice!, #symbolize_keys, #symbolize_keys!, #to_yaml

Instance Method Details

#[](key) ⇒ Object



22
23
24
25
# File 'lib/i18n/index/simple/data.rb', line 22

def [](key)
  key = Key.new(key) unless key.is_a?(Key)
  super
end

#[]=(key, value) ⇒ Object



27
28
29
30
# File 'lib/i18n/index/simple/data.rb', line 27

def []=(key, value)
  key = Key.new(key) unless key.is_a?(Key)
  super
end

#add(call) ⇒ Object



5
6
7
8
# File 'lib/i18n/index/simple/data.rb', line 5

def add(call)
  key = Key.new(call.full_key(true))
  occurences(key) << Occurence.new(key, call.filename, call.position)
end

#occurences(key) ⇒ Object



17
18
19
20
# File 'lib/i18n/index/simple/data.rb', line 17

def occurences(key)
 self[key] ||= { :occurences => [] }
 self[key][:occurences]
end

#remove(call) ⇒ Object



10
11
12
13
14
15
# File 'lib/i18n/index/simple/data.rb', line 10

def remove(call)
  key = Key.new(call.full_key(true))
  occurences = occurences(key)
  occurences.delete(Occurence.new(key, call.filename, call.position))
  self.delete(key) if occurences.empty?
end