class Barcoder::Base
Public Class Methods
new(attributes_or_json={})
click to toggle source
# File lib/barcoder/base.rb, line 5 def initialize(attributes_or_json={}) self.attributes = attributes_or_json end
Private Class Methods
response_to_attr(response)
click to toggle source
Class-level conversion of response to attributes
# File lib/barcoder/base.rb, line 37 def self.response_to_attr(response) data = response_to_json(response).with_indifferent_access data[:pages] = data[:pages].map {|p| Barcoder::Page.new(p)} if data[:pages] data end
response_to_json(response)
click to toggle source
# File lib/barcoder/base.rb, line 43 def self.response_to_json(response) Yajl::Parser.parse(response.body) end
Public Instance Methods
attributes=(attributes_or_json)
click to toggle source
# 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
Private Instance Methods
process_save_response(response)
click to toggle source
# File lib/barcoder/base.rb, line 24 def process_save_response(response) data = response_to_attr(response) self.attributes = data end
response_to_attr(response)
click to toggle source
Instance-level conversion of response to attributes
# File lib/barcoder/base.rb, line 30 def response_to_attr(response) data = self.class.response_to_attr(response) data.merge! persisted: true if respond_to?(:persisted=) data end
response_to_json(response)
click to toggle source
# File lib/barcoder/base.rb, line 47 def response_to_json(response) self.class.response_to_json response end