Class: Gillbus::Tariff::ReturnCause

Inherits:
Object
  • Object
show all
Extended by:
Fields
Includes:
UpdateAttrs
Defined in:
lib/gillbus/structs/tariff/return_cause.rb

Constant Summary collapse

LOSSLESS =
'lossless'.freeze

Class Method Summary collapse

Methods included from Fields

parse, parser, parser_class

Methods included from UpdateAttrs

#initialize, #update_attrs

Class Method Details

.parse(doc, instance: nil, parent: nil, options: {}) ⇒ Object

rubocop:disable Lint/UnusedMethodArgument



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gillbus/structs/tariff/return_cause.rb', line 14

def self.parse(doc, instance: nil, parent: nil, options: {})
  instance = new
  if doc.is_a?(Array) && doc.size == 2 && doc.first.is_a?(Hash) && doc.last.is_a?(String)
    instance.lossless = doc.first[LOSSLESS] == Parser::TRUE_CONST
    instance.cause = doc.last
  elsif doc.is_a?(Hash) && doc.has_key?('__content__')
    instance.lossless = (doc['lossless'] == 'true')
    instance.cause = doc['__content__']
  else
    instance.cause = doc
    instance.lossless = false
  end
  instance
end