Class: WeatherSage::CLI::Commands::NowCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/weather-sage/cli/commands/now.rb

Overview

Implementation of now command-line command.

Constant Summary collapse

HELP =

Help for this command.

Used by the help command.

{
  line: '
    Get current weather from station closest to address.
  '.strip,

  full: [
    'Get current weather at from station closest to address.',
  ].join("\n")
}.freeze
COL_NAMES =

CSV column names.

%w{
  address
  name
  type
  value
  unit
  quality_control
}.freeze

Instance Method Summary collapse

Methods inherited from Command

#initialize, run

Constructor Details

This class inherits a constructor from WeatherSage::CLI::Commands::Command

Instance Method Details

#run(args) ⇒ Object

Run now command.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/weather-sage/cli/commands/now.rb', line 35

def run(args)
  CSV(STDOUT) do |csv|
    # write column names
    csv << COL_NAMES

    # iterate over command-line arguments and write each one
    args.each do |arg|
      # geocode to first point
      if pt = geocode(arg).first
        # get first station
        if st = pt.point.stations.first
          # get latest observation data
          data = st.latest_observations

          # write observations
          make_rows(arg, data) do |row|
            csv << row
          end
        end
      end
    end
  end
end