Class: ApplicationSeeds::Attributes

Inherits:
Hash
  • Object
show all
Defined in:
lib/application_seeds/attributes.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Attributes

Returns a new instance of Attributes.



6
7
8
# File 'lib/application_seeds/attributes.rb', line 6

def initialize(attributes)
  super(attributes)
end

Instance Method Details

#map_attributes(mapping) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/application_seeds/attributes.rb', line 20

def map_attributes(mapping)
  mapping.stringify_keys!

  mapped = {}
  each do |k,v|
    if mapping.keys.include?(k)
      mapped[mapping[k].to_s] = v
    else
      mapped[k] = v
    end
  end
  Attributes.new(mapped)
end

#reject_attributes(*attribute_names) ⇒ Object



15
16
17
18
# File 'lib/application_seeds/attributes.rb', line 15

def reject_attributes(*attribute_names)
  attribute_names.map!(&:to_s)
  Attributes.new(reject { |k,v| attribute_names.include?(k) })
end

#select_attributes(*attribute_names) ⇒ Object



10
11
12
13
# File 'lib/application_seeds/attributes.rb', line 10

def select_attributes(*attribute_names)
  attribute_names.map!(&:to_s)
  Attributes.new(select { |k,v| attribute_names.include?(k) })
end