Class: WeatherBug::TransformableData
- Inherits:
-
Object
- Object
- WeatherBug::TransformableData
show all
- Defined in:
- lib/weatherbug/transformable_data.rb
Overview
This is a super-convenient class for transorming data and requiring things in the different associated WeatherBug data classes
Class Method Summary
collapse
Class Method Details
.from_document(document) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/weatherbug/transformable_data.rb', line 15
def self.from_document(document)
object = self.new
@transformers.each do |key, options|
value = document.xpath(key).text
next if value.nil?
value = TransformableData.send(options[:transform], value) if options.has_key?(:transform)
object.send("#{options[:name]}=", value)
end
object
end
|
7
8
9
10
11
12
13
|
# File 'lib/weatherbug/transformable_data.rb', line 7
def self.register_transformer(name, options = {})
@transformers ||= {}
options[:name] = name.split(/[:@]/).last.gsub('-', '_').to_sym unless options.has_key?(:name)
private; attr_writer options[:name]
public; attr_reader options[:name]
@transformers[name] = options
end
|