Class: Wettr::CLI
- Inherits:
-
Object
- Object
- Wettr::CLI
- Defined in:
- lib/wettr/cli.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
-
#initialize(args = nil) ⇒ CLI
constructor
A new instance of CLI.
- #parse_args ⇒ Object
- #print_help_menu ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args = nil) ⇒ CLI
Returns a new instance of CLI.
4 5 6 |
# File 'lib/wettr/cli.rb', line 4 def initialize(args = nil) @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
2 3 4 |
# File 'lib/wettr/cli.rb', line 2 def args @args end |
Instance Method Details
#parse_args ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wettr/cli.rb', line 18 def parse_args if args.include?("--help") 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 ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/wettr/cli.rb', line 31 def help_text = <<-HELP_TEXT Usage: wettr [options] \nOptions: --help # Print this menu --version # Print the version number --zip ZIP_CODE # Weather by zip/postal code \nDescription: wettr is a command line ruby gem to get current weather information using OpenWeatherMap's Current Weather API in conjunction with the ipapi.co IP address api. \n wettr can get current weather data using either a zip/postal code or an IP address. Simply type wettr to get started. \nExamples: wettr # Weather by current IP address location wettr --zip 10001 # Weather by zip/postal code for New York City wettr --zip 20001 # Weather by zip/postal code for Washington D.C. HELP_TEXT puts help_text end |
#run ⇒ Object
8 9 10 11 12 13 14 15 16 |
# 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 |