lib/gillbus/helpers/parser.rb in gillbus-0.14.3 vs lib/gillbus/helpers/parser.rb in gillbus-0.14.4
- old
+ new
@@ -13,14 +13,16 @@
@doc = doc
@fields = fields
end
def parse
- fields.each do |name:, key:, type:|
+ fields.each do |name:, key:, type:, root:|
raw_value =
if key.is_a?(Regexp)
doc.select { |k| k =~ key }
+ elsif root
+ doc[root] && doc[root][key]
else
doc[key]
end
value = make_one_or_many(type, raw_value)
instance.send "#{name}=", value unless value.nil?
@@ -95,6 +97,6 @@
def decimal(val)
BigDecimal.new(val)
end
end
-end
\ No newline at end of file
+end