Class: Quovo::Models::Base
- Inherits:
-
Object
- Object
- Quovo::Models::Base
show all
- Extended by:
- Forwardable
- Defined in:
- lib/quovo/models/base.rb
Direct Known Subclasses
Account, Brokerage, Challenge, Choice, Extra, IframeToken, Image, Portfolio, Position, Progress, Sync, Transaction, User, Webhook
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(props) ⇒ Base
Returns a new instance of Base.
17
18
19
20
21
|
# File 'lib/quovo/models/base.rb', line 17
def initialize(props)
props.each do |field, value|
instance_variable_set("@#{field}", value)
end
end
|
Class Method Details
.fields(fields = nil) ⇒ Object
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/quovo/models/base.rb', line 6
def self.fields(fields = nil)
if fields
@fields = fields.map(&:to_sym)
@fields.each do |field|
attr_reader field
end
else
@fields || []
end
end
|
Instance Method Details
#[](field) ⇒ Object
23
24
25
|
# File 'lib/quovo/models/base.rb', line 23
def [](field)
send(field)
end
|
#to_h ⇒ Object
33
34
35
|
# File 'lib/quovo/models/base.rb', line 33
def to_h
to_hash
end
|
#to_hash ⇒ Object
27
28
29
30
31
|
# File 'lib/quovo/models/base.rb', line 27
def to_hash
self.class.fields.map do |field|
[field, self[field]]
end.to_h
end
|