Class: PropertyDataLoader
- Inherits:
-
Object
- Object
- PropertyDataLoader
- Defined in:
- lib/cre_property_matcher/property_data_loader.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_property(property) ⇒ Object
- #csv_to_properties ⇒ Object
- #data ⇒ Object
-
#initialize(manner = :csv) ⇒ PropertyDataLoader
constructor
A new instance of PropertyDataLoader.
- #load_csv ⇒ Object
- #properties ⇒ Object
- #property_array ⇒ Object
- #property_data_path ⇒ Object
- #run ⇒ Object
- #run_and_return_properties ⇒ Object
Constructor Details
#initialize(manner = :csv) ⇒ PropertyDataLoader
6 7 8 9 10 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 6 def initialize(manner = :csv) @manner = manner @properties = [] @csv_data = nil end |
Class Method Details
.run_and_return_properties ⇒ Object
12 13 14 15 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 12 def self.run_and_return_properties pdl = PropertyDataLoader.new pdl.run_and_return_properties end |
Instance Method Details
#add_property(property) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 41 def add_property(property) if property.class == Property @properties << property else raise "Unable to Add Property because it is not of the Property Class" end end |
#csv_to_properties ⇒ Object
61 62 63 64 65 66 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 61 def csv_to_properties data.each do |row| property = Property.new(row) add_property(property) end end |
#data ⇒ Object
49 50 51 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 49 def data @csv_data end |
#load_csv ⇒ Object
57 58 59 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 57 def load_csv @csv_data = CSV.read(property_data_path, {headers: true}) end |
#properties ⇒ Object
29 30 31 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 29 def properties @properties end |
#property_array ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 33 def property_array result = [] properties.each do |property| result << property end result end |
#property_data_path ⇒ Object
53 54 55 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 53 def property_data_path File.("../training_data/large_property_data.csv", __FILE__) end |
#run ⇒ Object
17 18 19 20 21 22 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 17 def run if @manner && @manner == :csv load_csv if data.nil? csv_to_properties end end |
#run_and_return_properties ⇒ Object
24 25 26 27 |
# File 'lib/cre_property_matcher/property_data_loader.rb', line 24 def run_and_return_properties run property_array end |