Sha256: 6d1c4c4b7036828ed7525051bcd45770b0a0d388edfdc665d2e0a5b012a99cc3
Contents?: true
Size: 900 Bytes
Versions: 2
Compression:
Stored size: 900 Bytes
Contents
module Extract class HashBuilder < Base INTERNAL_FIELDS = %i[array_of keep_if within unescape].freeze 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 def keep_hash?(hash, props) expression = props[:keep_if] expression.present? ? Expression.new(expression, hash).evaluate : true end 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
xml_data_extractor-0.5.0 | lib/src/extract/hash_builder.rb |
xml_data_extractor-0.4.0 | lib/src/extract/hash_builder.rb |