Class: Quincunx::Extractor
- Inherits:
-
Object
- Object
- Quincunx::Extractor
- Defined in:
- lib/quincunx/extractor.rb
Instance Method Summary collapse
- #extract ⇒ Object
-
#initialize(matcher, value) ⇒ Extractor
constructor
A new instance of Extractor.
- #values ⇒ Object
Constructor Details
#initialize(matcher, value) ⇒ Extractor
Returns a new instance of Extractor.
5 6 7 8 |
# File 'lib/quincunx/extractor.rb', line 5 def initialize(matcher, value) @matcher = matcher @value = value end |
Instance Method Details
#extract ⇒ Object
10 11 12 |
# File 'lib/quincunx/extractor.rb', line 10 def extract as ? values.merge(as.to_sym => value) : values end |
#values ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/quincunx/extractor.rb', line 14 def values case keys when Array keys.reduce({}) { |acc, k| acc.merge(k => value.send(k)) } when Hash keys.reduce({}) { |acc, (k, v)| acc.merge(v.to_sym => value.send(k)) } end end |