class Property

Public Class Methods

new(data) click to toggle source
# File lib/cre_property_matcher/property.rb, line 10
def initialize(data)
        @distance = 50000
        if data.class == CSV::Row
                load_from_csv_row(data)
        elsif data.class == Hash
                load_from_hash(data)
        end
        clean_property_types
        clean_money_values
        clean_percentages
        parse_dates
end

Public Instance Methods

calculate_distance_from_neighbors(neighbors, features, scales) click to toggle source
# File lib/cre_property_matcher/property.rb, line 23
def calculate_distance_from_neighbors(neighbors, features, scales)
        neighbors.each do |neighbor|
                values = []
                features.each do |feature|
                        neighbor_value = neighbor.instance_variable_get(feature)
                        feature_delta = neighbor_value.nil? ?  1 : (neighbor_value - self.instance_variable_get(feature))
                        feature_delta = feature_delta / scales[feature][:range].to_f
                        value = feature_delta * feature_delta
                        values << value
                end

                unless neighbor.general_property_type == self.general_property_type
                        values << 0.005
                end
                
                neighbor.distance = Math.sqrt(values.reduce(:+))
        end
end
clean_money_values() click to toggle source
# File lib/cre_property_matcher/property.rb, line 92
def clean_money_values
        attrs = ["noi", "ncf", "loan_amount", "appraised_value", "annual_debt_service", "uw_revenue", "uw_expenses"]
        
        attrs.each do |attr|
                value = instance_variable_get(:"@#{attr}")
                instance_variable_set(:"@#{attr}", clean_money(value))
        end
end
clean_percentages() click to toggle source
# File lib/cre_property_matcher/property.rb, line 101
def clean_percentages
        attrs = ["ltv", "interest_rate", "occupancy"]
        
        attrs.each do |attr|
                value = instance_variable_get(:"@#{attr}")
                instance_variable_set(:"@#{attr}", clean_percentage(value))
        end
end
clean_property_types() click to toggle source
# File lib/cre_property_matcher/property.rb, line 82
def clean_property_types
        if @general_property_type.nil?
                return
        elsif @general_property_type.include?("Manufactured")
                @general_property_type = "Manufactured Housing"
        elsif @general_property_type == "Hospitality"
                @general_property_type = "Hotel"
        end
end
distance() click to toggle source
# File lib/cre_property_matcher/property.rb, line 42
def distance
        @distance
end
distance=(value) click to toggle source
# File lib/cre_property_matcher/property.rb, line 46
def distance=(value)
        @distance = value
end
load_from_csv_row(data) click to toggle source
# File lib/cre_property_matcher/property.rb, line 66
def load_from_csv_row(data)
        PropertyAttributes.attrs_to_sym_hash.each do |key, value|
                data_point = data[key]
                instance_variable_set(:"@#{value.to_s}", data_point)
        end
end
load_from_hash(data) click to toggle source
# File lib/cre_property_matcher/property.rb, line 73
def load_from_hash(data)
        if validate_hash(data)
                PropertyAttributes.attrs_to_sym_hash.each do |key, value|
                        data_point = data[value]
                        instance_variable_set(:"@#{value.to_s}", data_point)
                end
        end
end
parse_dates() click to toggle source
# File lib/cre_property_matcher/property.rb, line 110
def parse_dates
        attrs = ["loan_date", "maturity_date", "appraisal_date"]

        attrs.each do |attr|
                value = instance_variable_get(:"@#{attr}")
                instance_variable_set(:"@#{attr}", date_parsed(value))
        end
end
show(features = [:@appraised_value, :@noi, :@ncf, :@occupancy, :@uw_revenue, :@uw_expenses, :@distance, :@general_property_type]) click to toggle source
# File lib/cre_property_matcher/property.rb, line 50
def show(features = [:@appraised_value, :@noi, :@ncf, :@occupancy, :@uw_revenue, :@uw_expenses, :@distance, :@general_property_type])
        self.instance_variables.each do |i_var|
                value = instance_variable_get(i_var)
                puts "#{instance_variable_to_string(i_var)}: #{value}" if features.include?(i_var)
        end   
end
slice(features) click to toggle source
# File lib/cre_property_matcher/property.rb, line 57
def slice(features)
        instance_variables.each_with_object({}) do |curr, acc|
                cleaned = curr.to_s.delete("@")
                if features.include?(cleaned)
                        acc[cleaned] = self.instance_variable_get(curr)
                end
        end   
end

Private Instance Methods

clean_money(value) click to toggle source
# File lib/cre_property_matcher/property.rb, line 138
def clean_money(value)
        value.to_s.strip.delete("$").delete(",").to_i if value
end
clean_percentage(value) click to toggle source
# File lib/cre_property_matcher/property.rb, line 125
def clean_percentage(value)
        return if value.nil?

        new_value = value.strip.delete("%").to_f
        if new_value > 100.0
                # puts "Property: #{@property_name} says it has a percentage greater than 100% =>  #{new_value}"
                new_value /= 100.0
                # puts "New Value: #{new_value}"
        end

        new_value / 100.0
end
date_parsed(value) click to toggle source
# File lib/cre_property_matcher/property.rb, line 121
def date_parsed(value)
        Date.strptime(value, "%m/%d/%y") if value
end
instance_variable_to_string(instance_variable) click to toggle source
# File lib/cre_property_matcher/property.rb, line 146
def instance_variable_to_string(instance_variable)
        instance_variable.to_s.delete("@").split("_").map(&:capitalize).join(" ")
end
validate_hash(hash) click to toggle source
# File lib/cre_property_matcher/property.rb, line 142
def validate_hash(hash)
        true                                  
end