Module: ReportUtils

Included in:
ClosedSale, EvalReport
Defined in:
lib/report_utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.average_land_val(comp_values) ⇒ Object

averages an array of floats



64
65
66
67
68
# File 'lib/report_utils.rb', line 64

def average_land_val(comp_values) # averages an array of floats
	sum = comp_values.inject(:+)
	ave = sum ? sum / comp_values.count : 0
	return Money.new(ave * 100, 'USD')
end

.conditional_externs_array(doc) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/report_utils.rb', line 148

def self.conditional_externs_array(doc)
	# the array that will be returned and used by the prawn table
	full_array = [
			[{content: "Externalities, Wind Power Generation, Transmission Towers", colspan: 4}]
	]

	# row 1, will populate 3rd and 4th cells conditionally
	externs_array = [
			{content: "Are there any past uses of the property that may have 
				created hazardous waste contamination of the property or its groundwater?  If yes, describe:", colspan: 2}
	]

	# push affected by into externs array
	affected_by = doc[:property_affectedby]
	if affected_by && affected_by.any?
		externs_array.push("Description of Externalities that affect(s) this property:", affected_by.join(", "))
	end

	# conditional push of hazards and/or problems if exist
	hazards_and_problems = []
	if doc[:has_hazardous_waste] == "Yes"
		hazards_and_problems.push({content: doc[:hazard_descr], colspan: 2})
	else
		hazards_and_problems.push({content: "No", colspan: 2})
	end

	# check various fields for environmental or other problems 
	problems = []
	problems.push(doc[:problem_descr], doc[:env_problems], doc[:env_problem_descr])
	if problems && problems.any?
		hazards_and_problems.push("Description of problems, issues or resolve:", problems.join(". "))
	end

	# conditional push of tower and wind info
	towers_and_wind_type = []
	ttowers = doc[:ttowers]
	if ttowers && ttowers.any?
		towers_and_wind_type.push("Type of Transmission Tower on Property:", ttowers.join(", "))
	end

	wind = doc[:windgeneratortype]
	if wind && wind.any?
		towers_and_wind_type.push("Wind Power Generation Type:", wind.join(", "))
	end

	#conditional push of tower income and wind speed
	tt_income_and_wind_speed = []
	if doc[:tt_annual_income]
		tt_income_and_wind_speed.push("Annual net income from Transmission Tower Contracts:", doc[:tt_annual_income])
	end

	if doc[:windspeed]
		tt_income_and_wind_speed.push("Wind Speed Class:", doc[:windspeed])
	end

	# conditional push of transmission tower comments and number of wind gen towers
	tt_comments_and_wind_towers = []
	if doc[:transtower_comments]
		tt_comments_and_wind_towers.push("Transmission Tower Comments:", doc[:transtower_comments])
	end

	if doc[:num_of_gentowers]
		tt_comments_and_wind_towers.push("Number of Generation Towers:", doc[:num_of_gentowers])
	end

	# conditional push of tower info
	tower_height = ["", ""]
	if doc[:avgtowerhight]
		tower_height.push("Average Height of Generation Towers:", doc[:avgtowerhight])
	end

	wind_income = ["", ""]
	if doc[:windgenincome]
		wind_income.push("Net Annual Income Generate from Wind Generation Towers:", doc[:windgenincome])
	end

	wind_gen_comment = ["", ""]
	if doc[:windgen_comment]
		wind_gen_comment.push("Wind Generation Comments:", doc[:windgen_comment])
	end

	# push all subarrays into main array and return
	full_array.push(externs_array, hazards_and_problems, towers_and_wind_type, 
		tt_income_and_wind_speed, tt_comments_and_wind_towers, tower_height, wind_income, wind_gen_comment)

	return full_array
end

.maximum_land_val(comp_values) ⇒ Object

gets max value for array of floats



80
81
82
83
# File 'lib/report_utils.rb', line 80

def maximum_land_val(comp_values) # gets max value for array of floats
	max = comp_values.any? ? comp_values.max : 0
	return Money.new(max * 100, 'USD')
end

.median_land_val(comp_values) ⇒ Object

gets median value for an array of floats



71
72
73
74
75
76
77
# File 'lib/report_utils.rb', line 71

def median_land_val(comp_values) # gets median value for an array of floats
	sorted_array = comp_values.sort
	length = sorted_array.length

	median = sorted_array.any? ? (sorted_array[(length - 1) / 2] + sorted_array[length / 2]) / 2.0 : 0
	return Money.new(median * 100, 'USD')
end

.minimum_land_val(comp_values) ⇒ Object

gets min value for array of floats



86
87
88
89
# File 'lib/report_utils.rb', line 86

def minimum_land_val(comp_values) # gets min value for array of floats
	min = comp_values.any? ? comp_values.min : 0
	return Money.new(min * 100, 'USD')
end

.parallel_text(static, dyn, indent_distance) ⇒ Object

DRY parallel text gen method for text in the form: “Some Title:” “Some Data”



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/report_utils.rb', line 49

def parallel_text(static, dyn, indent_distance) # DRY parallel text gen method for text in the form: "Some Title:"				"Some Data"
	float do
		text static, style: :bold
	end

	indent(indent_distance) do
		if !dyn || dyn.empty?
			text " "
		else
			text dyn
		end
	end
end

.static_stringsObject



3
4
5
6
7
8
# File 'lib/report_utils.rb', line 3

def static_strings
	text_blocks = {}
	static_strings = YAML.load_file('./config/static_text.yml')
	static_strings.each {|k, v| text_blocks[k.to_sym] = v}
	return text_blocks
end

Instance Method Details

#datemaker(date_string) ⇒ Object

takes a string string value, avoid parse errors by checking for nil



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/report_utils.rb', line 21

def datemaker(date_string) # takes a string string value, avoid parse errors by checking for nil
	if date_string
		if date_string.class == Time
			ds = date_string.to_date.to_s
		else
			begin
				ds = Date.parse(date_string)
			rescue ArgumentError => ex
			end
		end
	end

	ds ||= ''
	return ds
end

#flip_improvements_array(improv_array, table_num) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/report_utils.rb', line 92

def flip_improvements_array(improv_array, table_num) 
	type, size, unit_of_measure, foundation, const_class = ["Type"], ["Size"], ["Unit of Measure"], ["Foundation"], ["Const. Class"]
	floor, const_quality, cond_utility, year_built = ["Floor"], ["Const. Quality"], ["Cond Utility"], ["Year Built"]
	total_econ_al, eff_age, remaining_al, rcn, def_maint = ["Total Economic AL"], ["Remaining AL:"], ["RCN:"], ["Deferred Maint:"], ["% Physical Deprec."] 
	phys_dep, func_dep, economic, total_cont_val = ["% Physical Deprec."], ["% Functional Deprec."], ["% Economic"], ["Total Cont. Value:"]
	
	if improv_array && improv_array.any?
		improv_array.each do |i|
			type.push("#{i[:improvtype]}")
			size.push("#{i[:unitsize]}")
			unit_of_measure.push("#{i[:unitdescr]}")
			foundation.push("#{i[:foundation]}")
			const_class.push("#{i[:constrclass]}")
			floor.push("#{i[:floor]}")
			const_quality.push("#{i[:qaulityconstr]}")
			cond_utility.push("#{i[:condition]}")
			year_built.push("#{i[:yearbuilt]}")
			total_econ_al.push("#{i[:totalecoage]}")
			eff_age.push("#{i[:effage]}")
			remaining_al.push("#{no_nil_number(i[:totalecoage]) - no_nil_number(i[:effage])}")
			rcn.push(moneymaker(i[:rplccost], true))
			def_maint.push("#{moneymaker(i[:deffmaintenance], false)}")

			eco_age = no_nil_number(i[:totalecoage])
			if eco_age == 0
				phys_dep.push("undef")
			else
				phys_dep.push("#{no_nil_number(i[:effage]) / eco_age}")
			end

			func_dep.push("#{i[:fnctldeprication]}")
			economic.push("#{i[:extdeprication]}")
			total_cont_val.push("#{moneymaker(i[:depval], false)}")
		end
	end

	if table_num == 1
		parsed_array = [
			[{content: "Improvements", colspan: 8}],
			%w(Description Imprv.1 Imprv.2 Imprv.3 Imprv.4 Imprv.5 Imprv.6 Imprv.7)
		]
	else
		parsed_array = [
			[{content: "Improvements Continued", colspan: 8}],
			%w(Description Imprv.8 Imprv.9 Imprv.10 Imprv.11 Imprv.12 Imprv.13 Imprv.14)
		]
	end
	
	parsed_array.push(type, size, unit_of_measure, foundation, const_class, floor, const_quality, cond_utility, year_built,
		total_econ_al, eff_age, remaining_al, rcn, def_maint, phys_dep, func_dep, economic, total_cont_val)
	# this method creates a 2 dimensional array to pass in to prawn table
	# it is necessary because of the reversed axis of the improvements table
	# there is likely a cleaner way to do this, but any solution should ensure a predictable array to pass to a prawn table
	# an array should contain 8 elements that can include nil or "" if such an attribute does not exist. 
end

#moneymaker(money_hash, without_cents) ⇒ Object

(12345, currency_iso: “USD”, boolean) # DRY currency string generation



11
12
13
14
15
16
17
18
19
# File 'lib/report_utils.rb', line 11

def moneymaker(money_hash, without_cents) # ({cents: 12345, currency_iso: "USD"}, boolean) # DRY currency string generation
	if money_hash
		m = Money.new(money_hash[:cents], money_hash[:currency_iso])
	else
		m = Money.new(0, "USD")
	end

	m.format(no_cents: without_cents)
end

#no_nil_array(array_hash) ⇒ Object

check for nodes for arrays that might be nil, return empty array



37
38
39
# File 'lib/report_utils.rb', line 37

def no_nil_array(array_hash) # check for nodes for arrays that might be nil, return empty array
	array_hash ||= []
end

#no_nil_number(my_num) ⇒ Object

check for nil nodes to avoid typerrors and NoMethod



41
42
43
# File 'lib/report_utils.rb', line 41

def no_nil_number(my_num) # check for nil nodes to avoid typerrors and NoMethod
	my_num ||= 0 
end

#no_nil_string(my_string) ⇒ Object

check for nil befor calling methods on it



45
46
47
# File 'lib/report_utils.rb', line 45

def no_nil_string(my_string) # check for nil befor calling methods on it
	my_string ||= ""
end