Class: ABBYY::Cloud::Model
- Inherits:
-
Object
- Object
- ABBYY::Cloud::Model
show all
- Extended by:
- Dry::Initializer::Mixin
- Defined in:
- lib/abbyy/cloud/model.rb
Direct Known Subclasses
ABBYY::Cloud::Models::Direction, ABBYY::Cloud::Models::Discount, ABBYY::Cloud::Models::Engine, ABBYY::Cloud::Models::Error, ABBYY::Cloud::Models::FileReference, ABBYY::Cloud::Models::FullOrder, ABBYY::Cloud::Models::OcrSettings, ABBYY::Cloud::Models::OcrStatistics, ABBYY::Cloud::Models::OcrWarning, ABBYY::Cloud::Models::OrderStatistics, ABBYY::Cloud::Models::Price, ABBYY::Cloud::Models::SourceSegment, ABBYY::Cloud::Models::SourceTag, ABBYY::Cloud::Models::TextStatistics, ABBYY::Cloud::Models::TransferData, ABBYY::Cloud::Models::Translation, ABBYY::Cloud::Models::TranslationLink, ABBYY::Cloud::Models::TranslationSegment, ABBYY::Cloud::Models::UnitPrice
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.attributes ⇒ Object
25
26
27
|
# File 'lib/abbyy/cloud/model.rb', line 25
def attributes
@attributes ||= []
end
|
.new(value) ⇒ Object
Also known as:
call, []
14
15
16
17
18
19
20
21
|
# 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) ⇒ Object
Also known as:
attribute, param
29
30
31
|
# File 'lib/abbyy/cloud/model.rb', line 29
def option(name, type = nil, as: nil, **opts)
super.tap { attributes << (as || name).to_sym }
end
|
Instance Method Details
#==(other) ⇒ Object
43
44
45
|
# File 'lib/abbyy/cloud/model.rb', line 43
def ==(other)
other.respond_to?(:to_h) ? to_h == other.to_h : false
end
|
#to_h ⇒ Object
47
48
49
50
51
52
|
# 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
|