class Paymill::Base
Attributes
app_id[R]
created_at[R]
id[R]
updated_at[R]
Public Class Methods
new( json )
click to toggle source
# File lib/paymill/models/base.rb, line 9 def initialize( json ) deserialize( json ) parse_timestamps end
Protected Class Methods
create_with?( incoming_arguments )
click to toggle source
# File lib/paymill/models/base.rb, line 15 def self.create_with?( incoming_arguments ) return false if mandatory_arguments.select { |a| incoming_arguments.include? a }.size < mandatory_arguments.size allowed_arguments.size == ( allowed_arguments | incoming_arguments ).size end
Protected Instance Methods
parse_timestamps()
click to toggle source
Parses UNIX timestamps and creates Time objects.
# File lib/paymill/models/base.rb, line 21 def parse_timestamps @created_at &&= Time.at( @created_at ) @updated_at &&= Time.at( @updated_at ) end
Private Instance Methods
deserialize( json )
click to toggle source
# File lib/paymill/models/base.rb, line 27 def deserialize( json ) json.each_pair do |key, value| case value.class.name when 'Array' if key.end_with?('s') instance_variable_set( "@#{key}", value.map { |e| (e.is_a? String) ? e : objectize( key[0...-1], e ) } ) else instance_variable_set( "@#{key}s", value.map { |e| (e.is_a? String) ? e : objectize( key, e ) } ) end when 'Hash' instance_variable_set( "@#{key}", objectize( key, value ) ) else instance_variable_set( "@#{key}", value ) end end end
objectize( clazz, hash )
click to toggle source
Converts the given 'hash' object into an instance of class with name stored in 'clazz' variable
# File lib/paymill/models/base.rb, line 45 def objectize( clazz, hash ) Module.const_get( "#{self.class.name.split( '::' ).first}::#{clazz.split('_').map(&:capitalize).join}" ).new( hash ) end