class Wettr::CLI

Attributes

args[R]

Public Class Methods

new(args = nil) click to toggle source
# File lib/wettr/cli.rb, line 4
def initialize(args = nil)
  @args = args
end

Public Instance Methods

parse_args() click to toggle source
# File lib/wettr/cli.rb, line 18
def parse_args
  if args.include?("--help")
    print_help_menu
  elsif args.include?("--version")
    puts "wettr #{Wettr::VERSION}"
  elsif zip = args[args.index("--zip") + 1]
    weather = Wettr::Weather.new_with_zip(zip)
    weather.print
  else
    puts "Please enter a zip code"
  end
end
print_help_menu() click to toggle source
run() click to toggle source
# File lib/wettr/cli.rb, line 8
def run
  if !args.empty?
    parse_args
  else
    ip = Wettr::IP.new_without_ip
    weather = Wettr::Weather.new_with_lat_and_lon(lat: ip.lat, lon: ip.lon)
    weather.print
  end
end