Class: OrangeData::ReceiptContent
- Inherits:
-
PayloadContent
- Object
- PayloadContent
- OrangeData::ReceiptContent
- Defined in:
- lib/orange_data/receipt.rb
Defined Under Namespace
Classes: AdditionalUserAttribute, AgentInfo, CheckClose, Payment, Position, SupplierInfo
Instance Attribute Summary collapse
-
#additional_user_attribute ⇒ Object
readonly
Returns the value of attribute additional_user_attribute.
-
#check_close ⇒ Object
readonly
Returns the value of attribute check_close.
-
#positions ⇒ Object
readonly
Returns the value of attribute positions.
Instance Method Summary collapse
- #add_payment(amount = nil, type = nil, **options) {|payment| ... } ⇒ Object
- #add_position(text = nil, **options) {|pos| ... } ⇒ Object
-
#initialize(payload = {}) ⇒ ReceiptContent
constructor
A new instance of ReceiptContent.
-
#raw_type ⇒ Object
сырой тип используется в qr_code.
- #set_additional_user_attribute(**options) ⇒ Object
- #set_agent_info(**options) ⇒ Object
- #to_hash ⇒ Object
Methods inherited from PayloadContent
#==, #as_json, #assign_attributes, #attributes, #to_json
Constructor Details
#initialize(payload = {}) ⇒ ReceiptContent
Returns a new instance of ReceiptContent.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/orange_data/receipt.rb', line 70 def initialize(payload={}) super(payload || {}) # TODO: import... # TODO: taxationSystem default in checkclose @check_close = CheckClose.new(@payload['checkClose']) if @payload["additionalUserAttribute"] @additional_user_attribute = AdditionalUserAttribute.new(@payload["additionalUserAttribute"]) end @positions = (@payload['positions'] || []).map{|pos| Position.new(pos) } end |
Instance Attribute Details
#additional_user_attribute ⇒ Object (readonly)
Returns the value of attribute additional_user_attribute.
188 189 190 |
# File 'lib/orange_data/receipt.rb', line 188 def additional_user_attribute @additional_user_attribute end |
#check_close ⇒ Object (readonly)
Returns the value of attribute check_close.
188 189 190 |
# File 'lib/orange_data/receipt.rb', line 188 def check_close @check_close end |
#positions ⇒ Object (readonly)
Returns the value of attribute positions.
188 189 190 |
# File 'lib/orange_data/receipt.rb', line 188 def positions @positions end |
Instance Method Details
#add_payment(amount = nil, type = nil, **options) {|payment| ... } ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/orange_data/receipt.rb', line 104 def add_payment(amount=nil, type=nil, **) payment = Payment.new payment.type = type if type payment.amount = amount if amount payment.assign_attributes() yield(payment) if block_given? check_close.payments << payment self end |
#add_position(text = nil, **options) {|pos| ... } ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/orange_data/receipt.rb', line 95 def add_position(text=nil, **) pos = Position.new pos.text = text if text pos.assign_attributes() yield(pos) if block_given? positions << pos self end |
#raw_type ⇒ Object
сырой тип используется в qr_code
83 84 85 |
# File 'lib/orange_data/receipt.rb', line 83 def raw_type @payload["type"] end |
#set_additional_user_attribute(**options) ⇒ Object
114 115 116 |
# File 'lib/orange_data/receipt.rb', line 114 def set_additional_user_attribute(**) @additional_user_attribute = AdditionalUserAttribute.new.assign_attributes() end |
#set_agent_info(**options) ⇒ Object
118 119 120 121 122 |
# File 'lib/orange_data/receipt.rb', line 118 def set_agent_info(**) # agent info may have some validations/transformations, so agent_info = AgentInfo.new.assign_attributes() assign_attributes(agent_info.attributes.compact) end |
#to_hash ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/orange_data/receipt.rb', line 87 def to_hash @payload.dup.tap{|h| h["positions"] = @positions.map(&:to_hash) h["checkClose"] = check_close.to_hash if check_close h["additionalUserAttribute"] = additional_user_attribute.to_hash if additional_user_attribute } end |