class Extract::HashBuilder

Constants

INTERNAL_FIELDS

Public Instance Methods

value(index = 0) click to toggle source
# File lib/src/extract/hash_builder.rb, line 5
def value(index = 0)
  path, props = node.to_h.values_at(:path, :props)

  hash = {}
  props.each do |field_name, nested_props|
    next unless valuable_field? field_name, nested_props, index

    value = ValueBuilder.new(Node.new(nested_props, path), extractor).value
    hash[field_name.to_sym] = value if value.present?
  end

  keep_hash?(hash, props) ? hash : nil
end

Private Instance Methods

keep_hash?(hash, props) click to toggle source
# File lib/src/extract/hash_builder.rb, line 21
def keep_hash?(hash, props)
  expression = props[:keep_if]
  expression.present? ? Expression.new(expression, hash).evaluate : true
end
valuable_field?(field_name, props, index) click to toggle source
# File lib/src/extract/hash_builder.rb, line 26
def valuable_field?(field_name, props, index)
  return false if INTERNAL_FIELDS.include? field_name
  return false if index.positive? && Node.new(props, "").first_only?

  true
end