Sha256: e9b5a5eb022c4373ef48f94c3158eb906b567a06aeeb26a6b6cdd7f1c2c42f11
Contents?: true
Size: 1.79 KB
Versions: 6
Compression:
Stored size: 1.79 KB
Contents
require 'yardi/validator/resident_eventing' require_relative 'base' module Yardi module DocumentParser class Residents < Base SOAP_ACTION = 'GetResidents'.freeze def after_initialize(params) @property_id = params[:property_id] end private attr_reader :body, :property_id # @param body [Hash<String, Object>] the body of the XML response parsed # into a Hash # @return [Array<Yardi::Model::Resident>] # @raise [Yardi::Error::Base] if the response is invalid def parse_body(body) @body = body residents end def residents path = %w[MITS_ResidentData PropertyResidents Residents Resident] results = [result_node.dig(*path)].flatten.compact if results.empty? raise Error::NoResults, "Failed to get residents for yardi_property_id: #{property_id}" end results.map { |r| create_resident(r) } end # Creates a primary Resident after first creating Resident objects # for roommates under `OtherOccupants`. def create_resident(resident) roommate_nodes = resident.dig('OtherOccupants', 'OtherOccupant') roommates = roommate_nodes.nil? ? [] : create_roommates(roommate_nodes) Model::Resident.new(resident, type: 'primary', roommates: roommates) end # Creates roommates given `OtherOccupant` data. Note that this can # either be a Hash or Array, so we cast it to an Array from the start. def create_roommates(roommates) return unless roommates roommates = [roommates].flatten roommates.map do |r| Model::Resident.new(r, type: 'roommate') end end def validator_classes [Validator::ResidentEventing] end end end end
Version data entries
6 entries across 6 versions & 1 rubygems