class PaysonAPI::V1::Receiver
Constants
- FORMAT_STRING
Attributes
amount[RW]
email[RW]
first_name[RW]
last_name[RW]
primary[RW]
Public Class Methods
parse(data)
click to toggle source
# File lib/payson_api/v1/receiver.rb, line 29 def self.parse(data) [].tap do |receivers| i = 0 while data[format(FORMAT_STRING, i, 'email')] receivers << new.tap do |r| r.email = CGI.unescape(data[format(FORMAT_STRING, i, 'email')].to_s) r.amount = data[format(FORMAT_STRING, i, 'amount')] r.first_name = CGI.unescape(data[format(FORMAT_STRING, i, 'firstName')].to_s) r.last_name = CGI.unescape(data[format(FORMAT_STRING, i, 'lastName')].to_s) r.primary = data[format(FORMAT_STRING, i, 'primary')] end i += 1 end end end
to_hash(receivers)
click to toggle source
# File lib/payson_api/v1/receiver.rb, line 11 def self.to_hash(receivers) {}.tap do |hash| receivers.each_with_index do |receiver, index| raise 'Invalid receiver' unless receiver.instance_of?(self) hash.merge!({ format(FORMAT_STRING, index, 'email') => receiver.email, format(FORMAT_STRING, index, 'amount') => receiver.amount, format(FORMAT_STRING, index, 'firstName') => receiver.first_name, format(FORMAT_STRING, index, 'lastName') => receiver.last_name, format(FORMAT_STRING, index, 'primary') => receiver.primary }) hash[format(FORMAT_STRING, index, 'firstName')] = receiver.first_name if receiver.first_name hash[format(FORMAT_STRING, index, 'lastName')] = receiver.last_name if receiver.last_name end end end