Sha256: c65e305854c90c6c9b6bbd2cd5ea9ab1cbea4237dc7bfe638663fcc710d89b89

Contents?: true

Size: 355 Bytes

Versions: 15

Compression:

Stored size: 355 Bytes

Contents

module Peddler
  # @api private
  class StructuredList
    def initialize(*keys)
      @keys = keys
    end

    def build(vals)
      Array(vals)
        .each_with_index
        .reduce(Hash.new) { |hsh, (v, i)| hsh.merge(compose_key(i + 1) => v) }
    end

    private

    def compose_key(index)
      (@keys.dup << index).join('.')
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
peddler-0.15.0 lib/peddler/structured_list.rb
peddler-0.14.0 lib/peddler/structured_list.rb
peddler-0.13.0 lib/peddler/structured_list.rb
peddler-0.12.7 lib/peddler/structured_list.rb
peddler-0.12.5 lib/peddler/structured_list.rb
peddler-0.12.4 lib/peddler/structured_list.rb
peddler-0.12.2 lib/peddler/structured_list.rb
peddler-0.12.1 lib/peddler/structured_list.rb
peddler-0.12.0 lib/peddler/structured_list.rb
peddler-0.11.1 lib/peddler/structured_list.rb
peddler-0.11.0 lib/peddler/structured_list.rb
peddler-0.10.0 lib/peddler/structured_list.rb
peddler-0.9.2 lib/peddler/structured_list.rb
peddler-0.9.1 lib/peddler/structured_list.rb
peddler-0.9.0 lib/peddler/structured_list.rb