Class: LocationImport
- Inherits:
-
ScaffoldLogic::DataImport
- Object
- ScaffoldLogic::DataImport
- LocationImport
- Defined in:
- app/models/location_import.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.save(upload) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'app/models/location_import.rb', line 2 def self.save(upload) # create file path _path = File.join('tmp', upload['datafile'].original_filename) # write file File.open(_path, 'wb') { |f| f.write(upload['datafile'].read) } self.run(_path) end |
.test(path = 'public/sample-locations.xls') ⇒ Object
12 13 14 |
# File 'app/models/location_import.rb', line 12 def self.test(path='public/sample-locations.xls') self.run(path) end |
Instance Method Details
#process_row ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/models/location_import.rb', line 16 def process_row @required_fields ||= [:'location_#'] if valid_row? && _location = Location.find_or_initialize_by(:location_number => row_map[@required_fields.first]) COLUMNS_BY_MODEL_FIELDS.keys.each do |_field| _content = eval(COLUMNS_BY_MODEL_FIELDS[_field]) _location.send("#{_field}=", _content) unless _content.blank? end _location.validate_address! _location.localize else @errors << "Row #{@row_index}: Missing at least one required field: #{@required_fields * ', '}!" end end |