Sha256: fe52ce7e9b6b68b83d6488b92f4b7e31df2e4b75d43aa43e7e2becfbb8f92e02

Contents?: true

Size: 349 Bytes

Versions: 12

Compression:

Stored size: 349 Bytes

Contents

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

    def build(vals)
      Array(vals)
        .each_with_index
        .reduce({}) { |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

12 entries across 12 versions & 1 rubygems

Version Path
peddler-1.3.0 lib/peddler/structured_list.rb
peddler-1.2.0 lib/peddler/structured_list.rb
peddler-1.1.1 lib/peddler/structured_list.rb
peddler-1.1.0 lib/peddler/structured_list.rb
peddler-1.0.2 lib/peddler/structured_list.rb
peddler-1.0.1 lib/peddler/structured_list.rb
peddler-1.0.0 lib/peddler/structured_list.rb
peddler-0.19.0 lib/peddler/structured_list.rb
peddler-0.18.0 lib/peddler/structured_list.rb
peddler-0.17.1 lib/peddler/structured_list.rb
peddler-0.17.0 lib/peddler/structured_list.rb
peddler-0.16.0 lib/peddler/structured_list.rb