Module: Transcriber::Resource::Embeddable::Parser

Defined in:
lib/transcriber/resource/key/embeddable/parser.rb

Instance Method Summary collapse

Instance Method Details

#digg(input) ⇒ Object



16
17
18
# File 'lib/transcriber/resource/key/embeddable/parser.rb', line 16

def digg(input)
  input_path.inject(input) {|buffer, key| buffer = buffer[key]}
end

#from_hash(attrs, resource = nil) ⇒ Object



20
21
22
# File 'lib/transcriber/resource/key/embeddable/parser.rb', line 20

def from_hash(attrs, resource = nil)
  raw? ? attrs : super
end

#parse(item, resource = nil) ⇒ Object



5
6
7
8
9
10
# File 'lib/transcriber/resource/key/embeddable/parser.rb', line 5

def parse(item, resource = nil)
  return parse_fields(item) if fields
  value = digg(item)
  parsed_value = raw? ? value : resource_class.parse(value)
  one? ? parsed_value.first : parsed_value
end

#parse_fields(item) ⇒ Object



12
13
14
# File 'lib/transcriber/resource/key/embeddable/parser.rb', line 12

def parse_fields(item)
  convert_input_keys.call(fields).map {|field| item[field]}
end

#to_input!(value, resource, options = {}) ⇒ Object



24
25
26
27
28
# File 'lib/transcriber/resource/key/embeddable/parser.rb', line 24

def to_input!(value, resource, options = {})
  return {} if value.nil?
  fields ? to_multiple_input(value, options)
         : to_single_input(value, options)
end