Class: Lokale::Macro

Inherits:
Object
  • Object
show all
Defined in:
lib/lokale/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Macro

Returns a new instance of Macro.



83
84
85
86
# File 'lib/lokale/model.rb', line 83

def initialize(name)
  @name = name
  clear_calls
end

Instance Attribute Details

#found_stringsObject (readonly)

Returns the value of attribute found_strings.



81
82
83
# File 'lib/lokale/model.rb', line 81

def found_strings
  @found_strings
end

#key_indexObject

Returns the value of attribute key_index.



80
81
82
# File 'lib/lokale/model.rb', line 80

def key_index
  @key_index
end

#localization_fileObject

Returns the value of attribute localization_file.



80
81
82
# File 'lib/lokale/model.rb', line 80

def localization_file
  @localization_file
end

#nameObject

Returns the value of attribute name.



80
81
82
# File 'lib/lokale/model.rb', line 80

def name
  @name
end

#note_indexObject

Returns the value of attribute note_index.



80
81
82
# File 'lib/lokale/model.rb', line 80

def note_index
  @note_index
end

#project_fileObject

Returns the value of attribute project_file.



80
81
82
# File 'lib/lokale/model.rb', line 80

def project_file
  @project_file
end

#regexObject

Returns the value of attribute regex.



80
81
82
# File 'lib/lokale/model.rb', line 80

def regex
  @regex
end

Instance Method Details

#clear_callsObject



88
89
90
# File 'lib/lokale/model.rb', line 88

def clear_calls
  @found_strings = Hash.new { |h, k| h[k] = 0 }
end

#read_from(file) ⇒ Object



92
93
94
95
96
97
98
99
100
# File 'lib/lokale/model.rb', line 92

def read_from(file)
  file.scan(@regex) do |m| 
  	lang = Config.get.main_lang
  	key = m[key_index] unless key_index.nil?
  	val = m[note_index] unless note_index.nil?
  	lstr = LString.new(key, val, val, lang)
  	@found_strings[lstr] += 1 
  end
end

#total_countObject



106
107
108
# File 'lib/lokale/model.rb', line 106

def total_count
  @found_strings.values.reduce(:+) || 0
end

#uniq_countObject



102
103
104
# File 'lib/lokale/model.rb', line 102

def uniq_count
  @found_strings.size
end