Class: Lokale::Macro
- Inherits:
-
Object
- Object
- Lokale::Macro
- Defined in:
- lib/lokale.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#found_strings ⇒ Object
readonly
Returns the value of attribute found_strings.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
Instance Method Summary collapse
- #clear_calls ⇒ Object
-
#initialize(name, regex, file_name) ⇒ Macro
constructor
A new instance of Macro.
- #read_from(file) ⇒ Object
- #total_count ⇒ Object
- #uniq_count ⇒ Object
Constructor Details
#initialize(name, regex, file_name) ⇒ Macro
Returns a new instance of Macro.
107 108 109 110 111 112 |
# File 'lib/lokale.rb', line 107 def initialize(name, regex, file_name) @name = name @regex = regex @file_name = file_name clear_calls end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
105 106 107 |
# File 'lib/lokale.rb', line 105 def file_name @file_name end |
#found_strings ⇒ Object (readonly)
Returns the value of attribute found_strings.
105 106 107 |
# File 'lib/lokale.rb', line 105 def found_strings @found_strings end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
105 106 107 |
# File 'lib/lokale.rb', line 105 def name @name end |
#regex ⇒ Object (readonly)
Returns the value of attribute regex.
105 106 107 |
# File 'lib/lokale.rb', line 105 def regex @regex end |
Instance Method Details
#clear_calls ⇒ Object
114 115 116 |
# File 'lib/lokale.rb', line 114 def clear_calls @found_strings = Hash.new { |h, k| h[k] = 0 } end |
#read_from(file) ⇒ Object
118 119 120 |
# File 'lib/lokale.rb', line 118 def read_from(file) file.scan(@regex) { |m| @found_strings[m] += 1 } end |
#total_count ⇒ Object
126 127 128 |
# File 'lib/lokale.rb', line 126 def total_count @found_strings.values.reduce(:+) || 0 end |
#uniq_count ⇒ Object
122 123 124 |
# File 'lib/lokale.rb', line 122 def uniq_count @found_strings.size end |