Module: Shippinglogic::Attributes::InstanceMethods

Defined in:
lib/shippinglogic/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject

Returns a hash of the various attribute values



50
51
52
53
54
55
56
# File 'lib/shippinglogic/attributes.rb', line 50

def attributes
  attributes = {}
  attribute_names.each do |name|
    attributes[name] = send(name)
  end
  attributes
end

#attributes=(value) ⇒ Object

Accepts a hash of attribute values and sets each attribute to those values



59
60
61
62
63
64
65
# File 'lib/shippinglogic/attributes.rb', line 59

def attributes=(value)
  return if value.blank?
  value.each do |key, value|
    next if !attribute_names.include?(key.to_sym)
    send("#{key}=", value)
  end
end

#initialize(*args) ⇒ Object

A convenience so that you can set attributes while initializing an object



43
44
45
46
47
# File 'lib/shippinglogic/attributes.rb', line 43

def initialize(*args)
  attributes = args.last.is_a?(Hash) ? args.last : {}
  @attributes = {}
  self.attributes = attributes
end