Class: CSVGeocoder::Sources::CSV

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_geocoder/sources/csv.rb

Instance Method Summary collapse

Constructor Details

#initialize(prompt) ⇒ CSV

Returns a new instance of CSV.



5
6
7
# File 'lib/csv_geocoder/sources/csv.rb', line 5

def initialize(prompt)
  @prompt = prompt
end

Instance Method Details

#askObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/csv_geocoder/sources/csv.rb', line 9

def ask
  csv = nil
  until csv
    begin
      csv_path = @prompt.ask("Hi, whats the path to your CSV?", required: true)
      csv ||= ::CSV.read(csv_path, headers: true)
    rescue Errno::ENOENT
      @prompt.error "Thats not a valid CSV path, please enter it again"
      @prompt.warn "If you're on mac, right click the file, hold option, then click copy as pathname"
    end
  end
  csv
end