Class: Remi::Fields

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/remi/fields.rb

Instance Method Summary collapse

Constructor Details

#initialize(fields = Hash.new({})) ⇒ Fields

Returns a new instance of Fields.



3
4
5
6
# File 'lib/remi/fields.rb', line 3

def initialize(fields=Hash.new({}))
  @fields = Hash.new({}).merge fields
  super(@fields)
end

Instance Method Details

#dupObject



9
10
11
# File 'lib/remi/fields.rb', line 9

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

#merge(other_fields, prefix: nil) ⇒ Object



13
14
15
# File 'lib/remi/fields.rb', line 13

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

#merge!(other_fields, prefix: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/remi/fields.rb', line 17

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