Sha256: b40a50fb0d1c12d0176d0956dbca75742314f8037321ec2f4954671cddc16b41

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

module TopsConnect
  class Property < Base
    def property_key
      data['Key']
    end
    alias id property_key

    def account_number
      data['AccountNumber']
    end

    def address
      [*address_lines_with_unit_number, city_state_zip]
        .map(&:strip)
        .select { |line| line.match?(/[[:graph:]]/) }
        .join("\n")
    end

    def community_key
      data['CommunityKey']
    end

    def modified_date
      return unless data['Metadata']['ModifiedDate']

      Time.parse data['Metadata']['ModifiedDate']
    end
    alias updated_at modified_date

    def city_state_zip
      "#{property['City']}, #{property['State']} #{property['Zip']}"
    end

    protected

    def property
      @property ||= data['Addresses']
        .find { |row| row.dig('Type', 'Name') == 'Property' }
    end

    # Sometimes the unit number is alone on the second line
    def address_lines_with_unit_number
      if property['AddressLine2'].match?(/\A\d+\z/)
        return ["#{property['AddressLine1']} ##{property['AddressLine2']}"]
      end

      [
        property['AddressLine1'],
        property['AddressLine2']
      ]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tops_connect-0.6.3 lib/tops_connect/property.rb