Sha256: 5dd3283cd86639eb1cc9909123dadacbcf31ff7173e32f512721c3d16b2ff42b

Contents?: true

Size: 405 Bytes

Versions: 6

Compression:

Stored size: 405 Bytes

Contents

# frozen_string_literal: true

module Peddler
  # @!visibility 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

6 entries across 6 versions & 1 rubygems

Version Path
peddler-2.4.5 lib/peddler/structured_list.rb
peddler-2.4.4 lib/peddler/structured_list.rb
peddler-2.4.3 lib/peddler/structured_list.rb
peddler-2.4.1 lib/peddler/structured_list.rb
peddler-2.4.0 lib/peddler/structured_list.rb
peddler-2.3.0 lib/peddler/structured_list.rb