Class: DataMiner::Dictionary
- Inherits:
-
Object
- Object
- DataMiner::Dictionary
- Defined in:
- lib/data_miner/dictionary.rb
Overview
An easy way to translate data before importing it using an intermediate table.
Constant Summary collapse
- DEFAULT_CASE_SENSITIVE =
true
Instance Attribute Summary collapse
-
#case_sensitive ⇒ TrueClass, FalseClass
readonly
Whether to be case-sensitive with lookups.
-
#key_name ⇒ String
readonly
What field in the dictionary holds the lookup key.
-
#sprintf ⇒ String
readonly
A
sprintf
-style format to be applied. -
#url ⇒ String
readonly
The URL of the dictionary.
-
#value_name ⇒ String
readonly
What field in the dictionary holds the final value.
Instance Method Summary collapse
-
#lookup(value) ⇒ nil, String
Look up a translation for a value.
Instance Attribute Details
#case_sensitive ⇒ TrueClass, FalseClass (readonly)
Whether to be case-sensitive with lookups. Defaults to false.
30 31 32 |
# File 'lib/data_miner/dictionary.rb', line 30 def case_sensitive @case_sensitive end |
#key_name ⇒ String (readonly)
What field in the dictionary holds the lookup key.
In other words, the column we scan down to find an entry.
13 14 15 |
# File 'lib/data_miner/dictionary.rb', line 13 def key_name @key_name end |
#sprintf ⇒ String (readonly)
A sprintf
-style format to be applied.
22 23 24 |
# File 'lib/data_miner/dictionary.rb', line 22 def sprintf @sprintf end |
#url ⇒ String (readonly)
The URL of the dictionary. It must be a CSV.
26 27 28 |
# File 'lib/data_miner/dictionary.rb', line 26 def url @url end |
#value_name ⇒ String (readonly)
What field in the dictionary holds the final value.
18 19 20 |
# File 'lib/data_miner/dictionary.rb', line 18 def value_name @value_name end |
Instance Method Details
#lookup(value) ⇒ nil, String
Look up a translation for a value.
46 47 48 49 50 51 |
# File 'lib/data_miner/dictionary.rb', line 46 def lookup(value) normalized_value = normalize_for_comparison value if match = table.detect { |entry| entry[key_name] == normalized_value } match[value_name].to_s end end |