class OrangeData::Document

main class for receipt/correction

Attributes

callback_url[RW]
content[RW]
group[RW]
id[RW]
inn[RW]
key_name[RW]

Public Class Methods

from_hash(hash) click to toggle source
# 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
new(id:SecureRandom.uuid, inn:, group:nil, key_name:nil, content:nil, callback_url: nil) { |content| ... } click to toggle source
# 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

Public Instance Methods

as_json() click to toggle source
# 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) click to toggle source
# File lib/orange_data/receipt.rb, line 49
def to_json(*args)
  as_json.to_json(*args)
end