Class: Quincunx::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/quincunx/extractor.rb

Instance Method Summary collapse

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

#extractObject



10
11
12
# File 'lib/quincunx/extractor.rb', line 10

def extract
  as ? values.merge(as.to_sym => value) : values
end

#valuesObject



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