Class: PropertyDataLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/cre_property_matcher/property_data_loader.rb

Class Method Summary collapse

Instance Method Summary collapse

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_propertiesObject



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_propertiesObject



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

#dataObject



49
50
51
# File 'lib/cre_property_matcher/property_data_loader.rb', line 49

def data
  @csv_data
end

#load_csvObject



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

#propertiesObject



29
30
31
# File 'lib/cre_property_matcher/property_data_loader.rb', line 29

def properties
  @properties
end

#property_arrayObject



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_pathObject



53
54
55
# File 'lib/cre_property_matcher/property_data_loader.rb', line 53

def property_data_path
  File.expand_path("../training_data/large_property_data.csv", __FILE__)   
end

#runObject



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_propertiesObject



24
25
26
27
# File 'lib/cre_property_matcher/property_data_loader.rb', line 24

def run_and_return_properties
  run
  property_array
end