data_miner 0.4.19 → 0.4.20
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/data_miner.gemspec +1 -1
- data/lib/data_miner/attribute.rb +25 -14
- data/lib/data_miner.rb +7 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.20
|
data/data_miner.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{data_miner}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.20"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Seamus Abshere", "Andy Rossmeissl"]
|
data/lib/data_miner/attribute.rb
CHANGED
@@ -6,12 +6,34 @@ module DataMiner
|
|
6
6
|
|
7
7
|
delegate :resource, :to => :step
|
8
8
|
|
9
|
+
VALID_OPTIONS = [
|
10
|
+
:from_units,
|
11
|
+
:to_units,
|
12
|
+
:static,
|
13
|
+
:dictionary,
|
14
|
+
:field_name,
|
15
|
+
:delimiter,
|
16
|
+
:split,
|
17
|
+
:units,
|
18
|
+
:sprintf,
|
19
|
+
:nullify,
|
20
|
+
:overwrite,
|
21
|
+
:upcase,
|
22
|
+
:units_field_name,
|
23
|
+
:units_field_number,
|
24
|
+
:field_number,
|
25
|
+
:chars
|
26
|
+
]
|
27
|
+
|
9
28
|
def initialize(step, name, options = {})
|
10
29
|
options.symbolize_keys!
|
11
|
-
@options = options
|
12
30
|
|
13
31
|
@step = step
|
14
32
|
@name = name
|
33
|
+
|
34
|
+
invalid_option_keys = options.keys.select { |k| not VALID_OPTIONS.include? k }
|
35
|
+
DataMiner.log_or_raise "Invalid options: #{invalid_option_keys.map(&:inspect).to_sentence} (#{inspect})" if invalid_option_keys.any?
|
36
|
+
@options = options
|
15
37
|
end
|
16
38
|
|
17
39
|
def inspect
|
@@ -83,8 +105,8 @@ module DataMiner
|
|
83
105
|
end
|
84
106
|
|
85
107
|
def do_convert(row, value)
|
86
|
-
DataMiner.log_or_raise "If you use :from_units, you need to set :to_units (#{
|
87
|
-
value.to_f.convert((from_units || unit_from_source(row)), to_units)
|
108
|
+
DataMiner.log_or_raise "If you use :from_units, you need to set :to_units (#{inspect})" unless wants_units?
|
109
|
+
value.to_f.convert((from_units || unit_from_source(row)), (to_units || unit_from_source(row)))
|
88
110
|
end
|
89
111
|
|
90
112
|
def do_sprintf(value)
|
@@ -151,23 +173,12 @@ module DataMiner
|
|
151
173
|
options[:split]
|
152
174
|
end
|
153
175
|
|
154
|
-
# Normal options
|
155
|
-
# %w(from_units to_units conditions sprintf nullify overwrite upcase units_field_name field_number chars static).each do |name|
|
156
|
-
# puts <<-EOS
|
157
|
-
# def #{name}
|
158
|
-
# options[:#{name}]
|
159
|
-
# end
|
160
|
-
# EOS
|
161
|
-
# end
|
162
176
|
def from_units
|
163
177
|
options[:from_units]
|
164
178
|
end
|
165
179
|
def to_units
|
166
180
|
options[:to_units] || options[:units]
|
167
181
|
end
|
168
|
-
def conditions
|
169
|
-
options[:conditions]
|
170
|
-
end
|
171
182
|
def sprintf
|
172
183
|
options[:sprintf]
|
173
184
|
end
|
data/lib/data_miner.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
require 'active_support'
|
2
|
+
require 'active_support/version'
|
3
|
+
%w{
|
4
|
+
active_support/core_ext/array/conversions
|
5
|
+
}.each do |active_support_3_requirement|
|
6
|
+
require active_support_3_requirement
|
7
|
+
end if ActiveSupport::VERSION::MAJOR == 3
|
8
|
+
|
2
9
|
require 'active_record'
|
3
10
|
require 'blockenspiel'
|
4
11
|
require 'conversions'
|