Class: Biggs::Extractor
- Inherits:
-
Object
- Object
- Biggs::Extractor
- Defined in:
- lib/biggs/extractor.rb
Instance Method Summary collapse
- #get_value(instance, field) ⇒ Object
- #get_values(instance) ⇒ Object
-
#initialize(options) ⇒ Extractor
constructor
A new instance of Extractor.
Constructor Details
Instance Method Details
#get_value(instance, field) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/biggs/extractor.rb', line 17 def get_value(instance, field) return if @value_methods[field] == false key = @value_methods[field] || field case key when Symbol instance.send(key.to_sym) when Proc key.call(instance).to_s when Array if key.all?{|it| it.is_a?(Symbol) } key.map{|method| instance.send(method) }.reject(&:blank?).join("\n") else raise "Biggs: Can't handle #{field} type Array with non-symbolic entries" end else raise "Biggs: Can't handle #{field} type #{key.class}" end end |
#get_values(instance) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/biggs/extractor.rb', line 10 def get_values(instance) Biggs::Formatter::FIELDS_WO_COUNTRY.inject({}) do |values, field| values[field] = get_value(instance, field) values end end |