class ABBYY::Cloud::Model
Public Class Methods
attributes()
click to toggle source
# File lib/abbyy/cloud/model.rb, line 25 def attributes @attributes ||= [] end
new(value)
click to toggle source
Calls superclass method
# File lib/abbyy/cloud/model.rb, line 14 def new(value) return value if value.is_a? self value = value.to_h.each_with_object({}) do |(key, val), obj| obj[key.to_sym] = val end super value end
option(name, type = nil, as: nil, **opts)
click to toggle source
Calls superclass method
# File lib/abbyy/cloud/model.rb, line 29 def option(name, type = nil, as: nil, **opts) super.tap { attributes << (as || name).to_sym } end
Private Class Methods
inherited(klass)
click to toggle source
Calls superclass method
# File lib/abbyy/cloud/model.rb, line 37 def inherited(klass) super klass.instance_variable_set :@attributes, attributes.dup end
Public Instance Methods
==(other)
click to toggle source
# File lib/abbyy/cloud/model.rb, line 43 def ==(other) other.respond_to?(:to_h) ? to_h == other.to_h : false end
to_h()
click to toggle source
# File lib/abbyy/cloud/model.rb, line 47 def to_h self.class.attributes.each_with_object({}) do |key, hash| val = send(key) hash[key] = hashify(val) unless val == Dry::Initializer::UNDEFINED end end
Private Instance Methods
hashify(value)
click to toggle source
# File lib/abbyy/cloud/model.rb, line 57 def hashify(value) if value.is_a? ABBYY::Cloud::Model value.to_h elsif value.respond_to? :to_hash value.to_hash .each_with_object({}) { |(key, val), obj| obj[key] = hashify(val) } elsif value.is_a? Enumerable value.map { |val| hashify(val) } else value end end