Sha256: 83d2fa5f4209c5bb7fa77e8f705899fc5a00f0374ff16b418088815c34e40a42

Contents?: true

Size: 595 Bytes

Versions: 11

Compression:

Stored size: 595 Bytes

Contents

module Remi
  class Fields < SimpleDelegator
    def initialize(fields=Hash.new({}))
      @fields = Hash.new({}).merge fields
      super(@fields)
    end


    def dup
      Fields.new(@fields.dup)
    end

    def merge(other_fields, prefix: nil)
      dup.merge!(other_fields, prefix: prefix)
    end

    def merge!(other_fields, prefix: nil)
      @fields.merge!(other_fields) do |key, this_val, other_val|
        if prefix
          @fields["#{prefix}#{key}".to_sym] = other_val
          this_val
        else
          this_val.merge other_val
        end
      end
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
remi-0.3.3 lib/remi/fields.rb
remi-0.3.2 lib/remi/fields.rb
remi-0.3.1 lib/remi/fields.rb
remi-0.3.0 lib/remi/fields.rb
remi-0.2.42 lib/remi/fields.rb
remi-0.2.41 lib/remi/fields.rb
remi-0.2.40 lib/remi/fields.rb
remi-0.2.39 lib/remi/fields.rb
remi-0.2.38 lib/remi/fields.rb
remi-0.2.37 lib/remi/fields.rb
remi-0.2.36 lib/remi/fields.rb