class NoaaWeatherClient::CLI

Constants

Coordinate

Attributes

buffer[W]
coordinate[R]

Public Class Methods

new(latitude, longitude) click to toggle source
# File lib/noaa_weather_client/cli.rb, line 13
def initialize(latitude, longitude)
  @coordinate = Coordinate.new(latitude, longitude)
  raise ArgumentError, "Invalid coordinate #{latitude}, #{longitude}" unless coordinate.valid?
end
postal_code_to_coordinate(postal_code, buffer = STDOUT) click to toggle source
# File lib/noaa_weather_client/cli.rb, line 5
def self.postal_code_to_coordinate(postal_code, buffer = STDOUT)
  client = NoaaWeatherClient.build_client
  coordinate = client.postal_code_to_coordinate postal_code
  buffer.puts Templates::PostalCode.new(coordinate).to_s
end

Public Instance Methods

render(*features) click to toggle source
# File lib/noaa_weather_client/cli.rb, line 18
def render(*features)
  features.each { |f| render_feature buffer, f }
end

Private Instance Methods

buffer() click to toggle source
# File lib/noaa_weather_client/cli.rb, line 36
def buffer
  @buffer || STDOUT
end
client() click to toggle source
# File lib/noaa_weather_client/cli.rb, line 40
def client
  @client ||= NoaaWeatherClient.build_client
end
render_feature(buffer, feature) click to toggle source
# File lib/noaa_weather_client/cli.rb, line 26
def render_feature(buffer, feature)
  if feature.to_s == 'observations'
    observations = client.current_observations(coordinate.latitude, coordinate.longitude)
    buffer.puts Templates::CurrentObservations.new(observations).to_s
  elsif feature.to_s == 'forecast'
    forecast = client.forecast_by_day(coordinate.latitude, coordinate.longitude)
    buffer.puts Templates::Forecast.new(forecast).to_s
  end
end