Class: RockRMS::Response::Base
- Inherits:
-
Object
- Object
- RockRMS::Response::Base
show all
- Defined in:
- lib/rock_rms/response/base.rb
Direct Known Subclasses
Attribute, AttributeValue, Batch, Block, BlockType, Campus, ContentChannel, ContentChannelItem, ContentChannelType, DefinedType, DefinedValue, ExceptionLog, Fund, Gateway, Group, GroupLocation, GroupMember, History, LavaShortcode, Location, Page, PaymentDetail, Person, PhoneNumber, RecurringDonation, RecurringDonationDetails, Registration, RegistrationInstance, SavedPaymentMethod, ServiceJob, SystemCommunication, SystemEmail, Transaction, TransactionDetail, UserLogin, WorkflowActionType, WorkflowActivityType, WorkflowType
Constant Summary
collapse
- BASE_MAPPING =
{
id: 'Id',
guid: 'Guid',
created_date_time: 'CreatedDateTime',
modified_date_time: 'ModifiedDateTime',
created_by_person_alias_id: 'CreatedByPersonAliasId',
attributes: 'Attributes',
attribute_values: 'AttributeValues',
foreign_key: 'ForeignKey'
}.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data) ⇒ Base
Returns a new instance of Base.
21
22
23
|
# File 'lib/rock_rms/response/base.rb', line 21
def initialize(data)
@data = data
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4
5
6
|
# File 'lib/rock_rms/response/base.rb', line 4
def data
@data
end
|
Class Method Details
17
18
19
|
# File 'lib/rock_rms/response/base.rb', line 17
def self.format(data)
new(data).format
end
|
Instance Method Details
25
26
27
28
29
30
31
|
# File 'lib/rock_rms/response/base.rb', line 25
def format
if data.is_a?(Array)
data.map { |item| format_single(item) }
else
format_single(data)
end
end
|
48
49
50
51
52
53
54
|
# File 'lib/rock_rms/response/base.rb', line 48
def format_attributes(res, klass)
return res if res.nil?
res.each_with_object({}) do |(attr, val), object|
object[attr] = klass.format(val)
end
end
|
#to_h(dict, data) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/rock_rms/response/base.rb', line 33
def to_h(dict, data)
return {} if data.nil?
dict
.merge(BASE_MAPPING)
.each_with_object({}) do |(l, r), object|
if l == :attributes || l == :attribute_values
format_klass = l == :attributes ? Attribute : AttributeValue
object[l] = format_attributes(data[r], format_klass)
else
object[l] = data[r]
end
end
end
|