Class: Transformers::ModelOutput
- Inherits:
-
Object
- Object
- Transformers::ModelOutput
show all
- Defined in:
- lib/transformers/utils/generic.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(**kwargs) ⇒ ModelOutput
Returns a new instance of ModelOutput.
29
30
31
|
# File 'lib/transformers/utils/generic.rb', line 29
def initialize(**kwargs)
@data = kwargs
end
|
Class Method Details
.attribute(attribute) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/transformers/utils/generic.rb', line 21
def self.attribute(attribute)
attributes << attribute.to_sym
define_method(attribute) do
self[attribute]
end
end
|
.attributes ⇒ Object
17
18
19
|
# File 'lib/transformers/utils/generic.rb', line 17
def self.attributes
@attributes ||= []
end
|
Instance Method Details
#[](k) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/transformers/utils/generic.rb', line 33
def [](k)
if k.is_a?(String) || k.is_a?(Symbol)
@data[k.to_sym]
else
to_tuple[k]
end
end
|
#to_tuple ⇒ Object
41
42
43
|
# File 'lib/transformers/utils/generic.rb', line 41
def to_tuple
self.class.attributes.map { |k| @data[k] }.compact
end
|