Sha256: edb42ca031d07f1da2d5efac29cf8222c5a87ba828ae183e58b0efb3a11c68e7

Contents?: true

Size: 397 Bytes

Versions: 9

Compression:

Stored size: 397 Bytes

Contents

# frozen_string_literal: true

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

    def build(vals)
      Array(vals)
        .flatten
        .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

9 entries across 9 versions & 1 rubygems

Version Path
peddler-2.1.1 lib/peddler/structured_list.rb
peddler-2.1.0 lib/peddler/structured_list.rb
peddler-2.0.4 lib/peddler/structured_list.rb
peddler-2.0.3 lib/peddler/structured_list.rb
peddler-2.0.0 lib/peddler/structured_list.rb
peddler-1.6.7 lib/peddler/structured_list.rb
peddler-1.6.6 lib/peddler/structured_list.rb
peddler-1.6.5 lib/peddler/structured_list.rb
peddler-1.6.4 lib/peddler/structured_list.rb