Sha256: 12b0dad63fb4ad6ae7ae1fefb1296e08a2d1c35a8cf3df936935bc065eb660d6

Contents?: true

Size: 804 Bytes

Versions: 5

Compression:

Stored size: 804 Bytes

Contents

module Attributor
  class FieldSelector
    class Transformer < Parslet::Transform

      rule(field: simple(:field_token), children: subtree(:children_tree)) do
        cs = if children_tree.empty?
          true
        else
          children_tree.each_with_object({}) do |item, hash|
            hash.merge! item
          end
        end
        { field_token.to_sym => cs }
      end

      rule(csv: subtree(:csv_tree)) do
        case csv_tree
        when ::Hash
          csv_tree
        when Array
          csv_tree.each_with_object({}) do |item, hash|
            hash.merge! item
          end
        else
          raise "Oops...didn't know this could happen! (this is not a Hash or an Array?). Got a #{csv_tree.class.name} : #{csv_tree.inspect}"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
attributor-5.0.2 lib/attributor/extras/field_selector/transformer.rb
attributor-5.0.1 lib/attributor/extras/field_selector/transformer.rb
attributor-5.0 lib/attributor/extras/field_selector/transformer.rb
attributor-4.2.0 lib/attributor/extras/field_selector/transformer.rb
attributor-4.1.0 lib/attributor/extras/field_selector/transformer.rb