Class: Fortnox::API::Mapper::Base
- Inherits:
-
Object
- Object
- Fortnox::API::Mapper::Base
- Defined in:
- lib/fortnox/api/mappers/base.rb
Direct Known Subclasses
Article, Customer, DefaultDeliveryTypes, DefaultTemplates, EDIInformation, EmailInformation, Invoice, InvoiceRow, Order, OrderRow, Project, TermsOfPayment, Unit
Constant Summary collapse
- Hash =
lambda do |hash| hash.each do |key, value| name = Fortnox::API::Mapper::Base.canonical_name_sym(value) hash[key] = Fortnox::API::Registry[name].call(value) end end
Class Method Summary collapse
Instance Method Summary collapse
Methods included from ToJSON
#entity_to_hash, included, #wrap_entity_json_hash
Methods included from FromJSON
#wrapped_json_collection_to_entities_hash, #wrapped_json_hash_to_entity_hash
Class Method Details
.canonical_name_sym(*values) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fortnox/api/mappers/base.rb', line 22 def self.canonical_name_sym(*values) klass = if values.empty? self elsif values.first.is_a? Class values.first else values.first.class end # For Ruby < 2.4, make sure we don't pass Bignum and Fixnum around klass = Integer if %w[Bignum Fixnum].include?(klass.to_s) # Stringify to avoid warnings on 2.4 klass.name.split('::').last.downcase.to_sym end |
Instance Method Details
#diff(entity_hash, parent_hash) ⇒ Object
37 38 39 40 |
# File 'lib/fortnox/api/mappers/base.rb', line 37 def diff(entity_hash, parent_hash) hash_diff(entity_hash[self.class::JSON_ENTITY_WRAPPER], parent_hash[self.class::JSON_ENTITY_WRAPPER]) end |