Class: DataMiner::Dictionary
- Inherits:
-
Object
- Object
- DataMiner::Dictionary
- Defined in:
- lib/data_miner/dictionary.rb
Instance Attribute Summary collapse
-
#key_name ⇒ Object
Returns the value of attribute key_name.
-
#sprintf ⇒ Object
Returns the value of attribute sprintf.
-
#table ⇒ Object
Returns the value of attribute table.
-
#value_name ⇒ Object
Returns the value of attribute value_name.
Instance Method Summary collapse
- #find(key_name, key, value_name, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Dictionary
constructor
A new instance of Dictionary.
- #lookup(key) ⇒ Object
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( = {}) @key_name = [:input] @value_name = [:output] @sprintf = [:sprintf] || '%s' @table = RemoteTable.new(:url => [:url]) end |
Instance Attribute Details
#key_name ⇒ Object
Returns the value of attribute key_name.
3 4 5 |
# File 'lib/data_miner/dictionary.rb', line 3 def key_name @key_name end |
#sprintf ⇒ Object
Returns the value of attribute sprintf.
3 4 5 |
# File 'lib/data_miner/dictionary.rb', line 3 def sprintf @sprintf end |
#table ⇒ Object
Returns the value of attribute table.
3 4 5 |
# File 'lib/data_miner/dictionary.rb', line 3 def table @table end |
#value_name ⇒ Object
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, = {}) if match = table.rows.detect { |row| normalize_for_comparison(key, ) == normalize_for_comparison(row[key_name], ) } 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 |