class RealPage::DocumentParser::GuestCards
Parse the ProspectSearch response
Constants
- MULTIPLE_CHILDREN
- SINGLE_CHILDREN
Private Instance Methods
children(guest_card)
click to toggle source
@return [Hash] the guest_card's children, parsed into RealPage::Models
# File lib/real_page/document_parser/guest_cards.rb, line 50 def children(guest_card) single_children(guest_card) .merge(multiple_children(guest_card)) .merge(custom_children(guest_card)) end
custom_children(guest_card)
click to toggle source
@return [Hash<String,RealPage::Model] the guest_card's children that
require more specialized parsing
# File lib/real_page/document_parser/guest_cards.rb, line 38 def custom_children(guest_card) {}.tap do |kids| if guest_card['Amentities'] kids['Amenities'] = Amenities.new.parse(guest_card['Amentities']) end if guest_card['Prospects'] kids['Prospects'] = Prospects.new.parse(guest_card['Prospects']) end end end
guest_cards(body)
click to toggle source
@return [Array<Hash<String, Object>>] an array of all GuestCard
attributes
# File lib/real_page/document_parser/guest_cards.rb, line 58 def guest_cards(body) response = body['prospectsearchResponse'] result = response['prospectsearchResult'] prospect_search = result['ProspectSearch'] if result return [] unless prospect_search guest_cards = prospect_search['GuestCards'] Utils::ArrayFetcher.new(hash: guest_cards, key: 'GuestCard').fetch end
multiple_children(guest_card)
click to toggle source
@return [Hash<String, Array<RealPage::Model>] the guest_card's children
that can have multiple entries
# File lib/real_page/document_parser/guest_cards.rb, line 69 def multiple_children(guest_card) Hash[ MULTIPLE_CHILDREN.map do |key, definition| fetcher = Utils::ArrayFetcher.new(definition.merge(hash: guest_card[key])) [key, fetcher.fetch] end ] end
parse_body(body)
click to toggle source
@param body [Hash<String, Object>] the body of the XML response parsed
into a Hash
@return [Array<RealPage::Model::GuestCard>] the guest_cards
contained
in the response
@raise [RealPage::Error::Base] if the response is invalid
# File lib/real_page/document_parser/guest_cards.rb, line 28 def parse_body(body) guest_cards(body).map do |guest_card| attrs = guest_card.merge(children(guest_card)) attrs.delete('Amentities') # Remove the misspelled version Model::GuestCard.new(attrs) end end
single_children(guest_card)
click to toggle source
@return [Hash<String,RealPage::Model] the guest_card's children that
have single entries
# File lib/real_page/document_parser/guest_cards.rb, line 81 def single_children(guest_card) Hash[ SINGLE_CHILDREN.map do |kid| [kid, Model.const_get(kid).new(guest_card[kid])] if guest_card[kid] end.compact ] end
validator_classes()
click to toggle source
# File lib/real_page/document_parser/guest_cards.rb, line 89 def validator_classes [Validator::ProspectsData] end