Class: Lokale::Macro

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (readonly)

Returns the value of attribute file_name.



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

def file_name
  @file_name
end

#found_stringsObject (readonly)

Returns the value of attribute found_strings.



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

def found_strings
  @found_strings
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#regexObject (readonly)

Returns the value of attribute regex.



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

def regex
  @regex
end

Instance Method Details

#clear_callsObject



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_countObject



126
127
128
# File 'lib/lokale.rb', line 126

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

#uniq_countObject



122
123
124
# File 'lib/lokale.rb', line 122

def uniq_count
  @found_strings.size
end