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
- #to_hash ⇒ Object
Methods inherited from PayloadContent
#==, #assign_attributes, #to_json
Constructor Details
#initialize(payload = {}) ⇒ ReceiptContent
Returns a new instance of ReceiptContent.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/orange_data/receipt.rb', line 51 def initialize(payload={}) @payload = payload || {} # TODO: import... # TODO: taxationSystem default in checkclose @check_close = CheckClose.new(@payload['checkClose']) @positions = (@payload['positions'] || []).map{|pos| Position.new(pos) } if @payload["additionalUserAttribute"] @additional_user_attribute = AdditionalUserAttribute.new(@payload["additionalUserAttribute"]) end end |
Instance Attribute Details
#additional_user_attribute ⇒ Object (readonly)
Returns the value of attribute additional_user_attribute.
165 166 167 |
# File 'lib/orange_data/receipt.rb', line 165 def additional_user_attribute @additional_user_attribute end |
#check_close ⇒ Object (readonly)
Returns the value of attribute check_close.
165 166 167 |
# File 'lib/orange_data/receipt.rb', line 165 def check_close @check_close end |
#positions ⇒ Object (readonly)
Returns the value of attribute positions.
165 166 167 |
# File 'lib/orange_data/receipt.rb', line 165 def positions @positions end |
Instance Method Details
#add_payment(amount = nil, type = nil, **options) {|payment| ... } ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/orange_data/receipt.rb', line 84 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
75 76 77 78 79 80 81 82 |
# File 'lib/orange_data/receipt.rb', line 75 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
63 64 65 |
# File 'lib/orange_data/receipt.rb', line 63 def raw_type @payload["type"] end |
#set_additional_user_attribute(**options) ⇒ Object
94 95 96 |
# File 'lib/orange_data/receipt.rb', line 94 def set_additional_user_attribute(**) @additional_user_attribute = AdditionalUserAttribute.new.assign_attributes() end |
#to_hash ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/orange_data/receipt.rb', line 67 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 |