Class: Lokale::Macro
- Inherits:
-
Object
- Object
- Lokale::Macro
- Defined in:
- lib/lokale/model.rb
Instance Attribute Summary collapse
-
#found_strings ⇒ Object
readonly
Returns the value of attribute found_strings.
-
#key_index ⇒ Object
Returns the value of attribute key_index.
-
#localization_file ⇒ Object
Returns the value of attribute localization_file.
-
#name ⇒ Object
Returns the value of attribute name.
-
#note_index ⇒ Object
Returns the value of attribute note_index.
-
#project_file ⇒ Object
Returns the value of attribute project_file.
-
#regex ⇒ Object
Returns the value of attribute regex.
Instance Method Summary collapse
- #clear_calls ⇒ Object
-
#initialize(name) ⇒ Macro
constructor
A new instance of Macro.
- #read_from(file) ⇒ Object
- #total_count ⇒ Object
- #uniq_count ⇒ Object
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_strings ⇒ Object (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_index ⇒ Object
Returns the value of attribute key_index.
80 81 82 |
# File 'lib/lokale/model.rb', line 80 def key_index @key_index end |
#localization_file ⇒ Object
Returns the value of attribute localization_file.
80 81 82 |
# File 'lib/lokale/model.rb', line 80 def localization_file @localization_file end |
#name ⇒ Object
Returns the value of attribute name.
80 81 82 |
# File 'lib/lokale/model.rb', line 80 def name @name end |
#note_index ⇒ Object
Returns the value of attribute note_index.
80 81 82 |
# File 'lib/lokale/model.rb', line 80 def note_index @note_index end |
#project_file ⇒ Object
Returns the value of attribute project_file.
80 81 82 |
# File 'lib/lokale/model.rb', line 80 def project_file @project_file end |
#regex ⇒ Object
Returns the value of attribute regex.
80 81 82 |
# File 'lib/lokale/model.rb', line 80 def regex @regex end |
Instance Method Details
#clear_calls ⇒ Object
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_count ⇒ Object
106 107 108 |
# File 'lib/lokale/model.rb', line 106 def total_count @found_strings.values.reduce(:+) || 0 end |
#uniq_count ⇒ Object
102 103 104 |
# File 'lib/lokale/model.rb', line 102 def uniq_count @found_strings.size end |