Class: Barcoder::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serializers::JSON, ActiveModel::Validations
Defined in:
lib/barcoder/base.rb

Direct Known Subclasses

Bucket, PDF, Page

Instance Method Summary collapse

Constructor Details

#initialize(attributes_or_json = {}) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/barcoder/base.rb', line 5

def initialize(attributes_or_json={})
  self.attributes = attributes_or_json
end

Instance Method Details

#attributes=(attributes_or_json) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/barcoder/base.rb', line 9

def attributes=(attributes_or_json)
  if attributes_or_json.is_a? String
    from_json(attributes_or_json)
    attributes = attributes.with_indifferent_access
  else
    attributes = attributes_or_json.with_indifferent_access
  end

  attributes.each do |field, val|
    send("#{field}=", val)
  end
end