Class: Property
Instance Method Summary
collapse
attrs_to_sym_hash, create_property_attributes
Constructor Details
#initialize(data) ⇒ Property
Returns a new instance of Property.
10
11
12
13
14
15
16
17
18
19
20
21
|
# 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
|
Instance Method Details
#calculate_distance_from_neighbors(neighbors, features, scales) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# 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 ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/cre_property_matcher/property.rb', line 83
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 ⇒ Object
92
93
94
95
96
97
98
99
|
# File 'lib/cre_property_matcher/property.rb', line 92
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 ⇒ Object
73
74
75
76
77
78
79
80
81
|
# File 'lib/cre_property_matcher/property.rb', line 73
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 ⇒ Object
42
43
44
|
# File 'lib/cre_property_matcher/property.rb', line 42
def distance
@distance
end
|
#distance=(value) ⇒ Object
46
47
48
|
# File 'lib/cre_property_matcher/property.rb', line 46
def distance=(value)
@distance = value
end
|
#load_from_csv_row(data) ⇒ Object
57
58
59
60
61
62
|
# File 'lib/cre_property_matcher/property.rb', line 57
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) ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/cre_property_matcher/property.rb', line 64
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 ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/cre_property_matcher/property.rb', line 101
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]) ⇒ Object
50
51
52
53
54
55
|
# 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
|