Class: Bs2Api::Entities::Customer
- Inherits:
-
Object
- Object
- Bs2Api::Entities::Customer
- Defined in:
- lib/bs2_api/entities/customer.rb
Constant Summary collapse
- TYPES =
{ personal: 'CPF', business: 'CNPJ' }
Instance Attribute Summary collapse
-
#business_name ⇒ Object
Returns the value of attribute business_name.
-
#document ⇒ Object
Returns the value of attribute document.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #business? ⇒ Boolean
- #first_name ⇒ Object
-
#initialize(args = {}) ⇒ Customer
constructor
A new instance of Customer.
- #last_name ⇒ Object
- #personal? ⇒ Boolean
- #to_hash ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Customer
Returns a new instance of Customer.
13 14 15 16 17 18 |
# File 'lib/bs2_api/entities/customer.rb', line 13 def initialize(args = {}) @document = args.fetch(:document, nil) @type = args.fetch(:type, 'CPF') @name = args.fetch(:name, nil) @business_name = args.fetch(:business_name, nil) end |
Instance Attribute Details
#business_name ⇒ Object
Returns the value of attribute business_name.
6 7 8 |
# File 'lib/bs2_api/entities/customer.rb', line 6 def business_name @business_name end |
#document ⇒ Object
Returns the value of attribute document.
6 7 8 |
# File 'lib/bs2_api/entities/customer.rb', line 6 def document @document end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/bs2_api/entities/customer.rb', line 6 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/bs2_api/entities/customer.rb', line 6 def type @type end |
Class Method Details
.from_response(hash_payload) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bs2_api/entities/customer.rb', line 31 def self.from_response(hash_payload) hash = ActiveSupport::HashWithIndifferentAccess.new(hash_payload) Bs2Api::Entities::Customer.new( document: hash["documento"], type: hash["tipoDocumento"], name: hash["nome"], business_name: hash["nomeFantasia"] ) end |
Instance Method Details
#business? ⇒ Boolean
46 47 48 |
# File 'lib/bs2_api/entities/customer.rb', line 46 def business? @type == TYPES[:business] end |
#first_name ⇒ Object
50 51 52 |
# File 'lib/bs2_api/entities/customer.rb', line 50 def first_name split_name.first end |
#last_name ⇒ Object
54 55 56 57 |
# File 'lib/bs2_api/entities/customer.rb', line 54 def last_name return '' if split_name.size <= 1 split_name.last end |
#personal? ⇒ Boolean
42 43 44 |
# File 'lib/bs2_api/entities/customer.rb', line 42 def personal? @type == TYPES[:personal] end |
#to_hash ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/bs2_api/entities/customer.rb', line 20 def to_hash ActiveSupport::HashWithIndifferentAccess.new( { "documento": @document, "tipoDocumento": @type, "nome": @name, "nomeFantasia": @business_name } ) end |