Class: OrangeData::Document
- Inherits:
-
Object
- Object
- OrangeData::Document
- Defined in:
- lib/orange_data/receipt.rb
Overview
main class for receipt/correction
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callback_url ⇒ Object
Returns the value of attribute callback_url.
-
#content ⇒ Object
Returns the value of attribute content.
-
#group ⇒ Object
Returns the value of attribute group.
-
#id ⇒ Object
Returns the value of attribute id.
-
#inn ⇒ Object
Returns the value of attribute inn.
-
#key_name ⇒ Object
Returns the value of attribute key_name.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(id: SecureRandom.uuid, inn:, group: nil, key_name: nil, content: nil, callback_url: nil) {|@content| ... } ⇒ Document
constructor
A new instance of Document.
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(id: SecureRandom.uuid, inn:, group: nil, key_name: nil, content: nil, callback_url: nil) {|@content| ... } ⇒ Document
Returns a new instance of Document.
16 17 18 19 20 21 22 23 24 |
# File 'lib/orange_data/receipt.rb', line 16 def initialize(id:SecureRandom.uuid, inn:, group:nil, key_name:nil, content:nil, callback_url: nil) @id = id @inn = inn @group = group @key_name = key_name || inn @content ||= content if content @callback_url = callback_url yield @content if block_given? end |
Instance Attribute Details
#callback_url ⇒ Object
Returns the value of attribute callback_url.
14 15 16 |
# File 'lib/orange_data/receipt.rb', line 14 def callback_url @callback_url end |
#content ⇒ Object
Returns the value of attribute content.
14 15 16 |
# File 'lib/orange_data/receipt.rb', line 14 def content @content end |
#group ⇒ Object
Returns the value of attribute group.
14 15 16 |
# File 'lib/orange_data/receipt.rb', line 14 def group @group end |
#id ⇒ Object
Returns the value of attribute id.
14 15 16 |
# File 'lib/orange_data/receipt.rb', line 14 def id @id end |
#inn ⇒ Object
Returns the value of attribute inn.
14 15 16 |
# File 'lib/orange_data/receipt.rb', line 14 def inn @inn end |
#key_name ⇒ Object
Returns the value of attribute key_name.
14 15 16 |
# File 'lib/orange_data/receipt.rb', line 14 def key_name @key_name end |
Class Method Details
.from_hash(hash) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/orange_data/receipt.rb', line 26 def self.from_hash(hash) new( id: hash[:id] || hash['id'], inn: hash[:inn] || hash['inn'], group: hash[:group] || hash['group'], key_name: hash[:key] || hash['key'], content: hash[:content] || hash['content'], callback_url: hash[:callbackUrl] || hash['callbackUrl'] ) end |
Instance Method Details
#as_json ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/orange_data/receipt.rb', line 37 def as_json { id: id, inn: inn, group: group || 'Main', content: content.is_a?(Hash) ? content : content.as_json, key: key_name }.tap{|h| h[:callbackUrl] = @callback_url if @callback_url } end |
#to_json(*args) ⇒ Object
49 50 51 |
# File 'lib/orange_data/receipt.rb', line 49 def to_json(*args) as_json.to_json(*args) end |