Sha256: 08092d3752bdb78777e1d1160c69b758a06d7dd6ab9e9b9ff7927b0c1884122e

Contents?: true

Size: 457 Bytes

Versions: 7

Compression:

Stored size: 457 Bytes

Contents

module Decanter
  module ValueParser
    class KeyValueSplitterParser < Base
      ITEM_DELIM = ','
      PAIR_DELIM = ':'

      result :raw

      parser do |name, val, options|
        item_delimiter = options.fetch(:item_delimiter, ITEM_DELIM)
        pair_delimiter = options.fetch(:pair_delimiter, PAIR_DELIM)
        val.split(item_delimiter).reduce({}) { |memo, pair| memo.merge( Hash[ *pair.split(pair_delimiter) ] ) }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decanter-0.7.1 lib/decanter/value_parser/key_value_splitter_parser.rb
decanter-0.7.0 lib/decanter/value_parser/key_value_splitter_parser.rb
decanter-0.6.3 lib/decanter/value_parser/key_value_splitter_parser.rb
decanter-0.6.2 lib/decanter/value_parser/key_value_splitter_parser.rb
decanter-0.6.1 lib/decanter/value_parser/key_value_splitter_parser.rb
decanter-0.6.0 lib/decanter/value_parser/key_value_splitter_parser.rb
decanter-0.5.5 lib/decanter/value_parser/key_value_splitter_parser.rb