module Amsi module RequestSection # Generate the AddGuestCard elements of an Amsi request class AddGuestCard # Formats dates and times like "mm/dd/yyyy", "02/14/2015" DATE_FORMAT = '%m/%d/%Y' private_constant :DATE_FORMAT def initialize( appointment_date: nil, comments: nil, contact_datetime: nil, contact_type:, date_needed: nil, initial_source_id: nil, lease_term_desired: nil, leasing_agent_id: nil, property_id:, prospect:, requirements: nil, qualified: nil, unit_subtype: nil, unit_type: nil ) @appointment_date = appointment_date @comments = comments @contact_datetime = contact_datetime @contact_type = contact_type @date_needed = date_needed @initial_source_id = initial_source_id @lease_term_desired = lease_term_desired @leasing_agent_id = leasing_agent_id @property_id = property_id @prospect = prospect @requirements = requirements @qualified = qualified @unit_subtype = unit_subtype @unit_type = unit_type end def generate(xml_builder) xml_builder.XMLData do |xml_data| xml_data.cdata edex.to_s end end private attr_reader :appointment_date, :comments, :contact_datetime, :contact_type, :date_needed, :initial_source_id, :lease_term_desired, :leasing_agent_id, :property_id, :prospect, :requirements, :qualified, :unit_subtype, :unit_type def edex Nokogiri::XML::Builder.new do |xml_builder| xml_builder.EDEX do |edex| edex.propertyid(property_id) edex.contacttype(contact_type) edex.contactdatetime(contact_time) if contact_datetime edex.modifieddate(format_date(Date.today)) edex.initialsourceid(initial_source_id) if initial_source_id edex.qualified(qualified ? 'Y' : 'N') unless qualified.nil? edex.leasetermdesired(lease_term_desired) if lease_term_desired edex.firstname(prospect.first_name) if prospect.first_name edex.lastname(prospect.last_name) edex.dateneeded(format_date(date_needed)) if date_needed edex.daytimephone(prospect.daytime_phone) if prospect.daytime_phone edex.email(prospect.email) if prospect.email edex.appointmentdate(appointment) if appointment_date edex.unittype(unit_type) if unit_type edex.unitsubtype(unit_subtype) if unit_subtype edex.leasingagentid(leasing_agent_id) if leasing_agent_id edex.requirements(requirements) if requirements edex.comments do |comments_xml| comments_xml.comment_(comments, date: format_date(Date.today)) end if comments end end.doc.root end def contact_time contact_datetime.strftime('%m/%d/%Y %0l:%M %p') end def appointment format_date(appointment_date) end def format_date(date) # Formats dates and times like "mm/dd/yyyy", "02/14/2015" date.strftime(DATE_FORMAT) end end end end