Class: CSVGeocoder::CLI
- Inherits:
-
Object
- Object
- CSVGeocoder::CLI
- Defined in:
- lib/csv_geocoder/cli.rb
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
- #start_geocoding ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
11 12 13 |
# File 'lib/csv_geocoder/cli.rb', line 11 def initialize @prompt = TTY::Prompt.new(interrupt: :exit) end |
Instance Method Details
#run ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/csv_geocoder/cli.rb', line 15 def run @csv = Sources::CSV.new(@prompt).ask puts @prompt.say "Thanks! I now need to know where to output your CSV", color: :bold @output_path = OutputPathRetriever.new(@prompt).ask_for_output_path puts @prompt.say "Great! I now need to know how you would like to geocode your CSV", color: :bold @geocode_method = GeocodeMethods::Retriever.new(@prompt).ask_for_type(@csv) puts @prompt.say "Awesome! I now need to know where you would like me to put the geocoded columns", color: :bold @output_columns = OutputColumnsRetriever.new(@prompt).ask_for_output_columns(@csv.headers) puts if @prompt.yes? "Start geocoding?" puts start_geocoding end end |
#start_geocoding ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/csv_geocoder/cli.rb', line 33 def start_geocoding = TTY::ProgressBar::Multi.new("[:bar] :percent :current/:total", style: { top: "", middle: "", bottom: ""}) geocode_progress = .register(":from -> :to", total: @csv.length) CSV.open(@output_path, "wb") do |new_csv| new_csv << @csv.headers @csv.each.with_index do |row, row_num| new_row = Sources::CSVRow.new(row, @geocode_method) new_row.update_columns!(@output_columns) new_csv << new_row.to_ary geocode_progress.advance( from: new_row.searching_by.to_s, to: new_row.output_string ) end end puts @prompt.ok "Completed!" end |