Class: DataMiner::Dictionary

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Dictionary

Returns a new instance of Dictionary.



5
6
7
8
9
10
# File 'lib/data_miner/dictionary.rb', line 5

def initialize(options = {})
  @key_name = options[:input]
  @value_name = options[:output]
  @sprintf = options[:sprintf] || '%s'
  @table = RemoteTable.new(:url => options[:url])
end

Instance Attribute Details

#key_nameObject

Returns the value of attribute key_name.



3
4
5
# File 'lib/data_miner/dictionary.rb', line 3

def key_name
  @key_name
end

#sprintfObject

Returns the value of attribute sprintf.



3
4
5
# File 'lib/data_miner/dictionary.rb', line 3

def sprintf
  @sprintf
end

#tableObject

Returns the value of attribute table.



3
4
5
# File 'lib/data_miner/dictionary.rb', line 3

def table
  @table
end

#value_nameObject

Returns the value of attribute value_name.



3
4
5
# File 'lib/data_miner/dictionary.rb', line 3

def value_name
  @value_name
end

Instance Method Details

#find(key_name, key, value_name, options = {}) ⇒ Object



16
17
18
19
20
# File 'lib/data_miner/dictionary.rb', line 16

def find(key_name, key, value_name, options = {})
  if match = table.rows.detect { |row| normalize_for_comparison(key, options) == normalize_for_comparison(row[key_name], options) }
    match[value_name].to_s
  end
end

#lookup(key) ⇒ Object



12
13
14
# File 'lib/data_miner/dictionary.rb', line 12

def lookup(key)
  find(self.key_name, key, self.value_name, :sprintf => self.sprintf)
end