Class: TSPScraper::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/tsp_scraper/cli.rb

Class Method Summary collapse

Class Method Details



17
18
19
20
# File 'lib/tsp_scraper/cli.rb', line 17

def self.print_help
  puts "Usage: tsp_scraper START_DATE END_DATE"
  puts "START_DATE and END_DATE should be in the format YYYY-MM-DD."
end


22
23
24
25
26
27
28
# File 'lib/tsp_scraper/cli.rb', line 22

def self.print_quotes(quotes)
  quotes.each do |quote|
    quote[:funds].each do |name, price|
      puts "#{quote[:date]},#{name},#{price.to_s('F')}"
    end
  end
end

.startObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/tsp_scraper/cli.rb', line 3

def self.start
  begin
    end_date_raw = ARGV.pop
    start_date_raw = ARGV.pop
    start_date = Date.parse(start_date_raw)
    end_date = Date.parse(end_date_raw)
  rescue
    print_help
    exit 1
  end
  quotes = TSPScraper::Client.scrape(start_date, end_date)
  print_quotes quotes
end