Module: WeatherCli::Cli
- Defined in:
- lib/weathercli/cli.rb
Class Method Summary collapse
- .config_file ⇒ Object
- .location ⇒ Object
- .location_args ⇒ Object
- .save_default_location(location) ⇒ Object
- .user_input ⇒ Object
Class Method Details
.config_file ⇒ Object
23 24 25 |
# File 'lib/weathercli/cli.rb', line 23 def config_file File.join(Dir.home, ".weathercli") end |
.location ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/weathercli/cli.rb', line 6 def location if location_args print "Save as default location? [y/n]: " if user_input.downcase == 'y' save_default_location(location_args) end location_args elsif File.file?(config_file) File.read(config_file) else print "Add default location [e.g. San Francisco, CA]: " location = user_input save_default_location(location) location end end |
.location_args ⇒ Object
35 36 37 |
# File 'lib/weathercli/cli.rb', line 35 def location_args ARGV.join unless ARGV.empty? end |
.save_default_location(location) ⇒ Object
27 28 29 |
# File 'lib/weathercli/cli.rb', line 27 def save_default_location(location) File.open(config_file, 'w').write(location) end |
.user_input ⇒ Object
31 32 33 |
# File 'lib/weathercli/cli.rb', line 31 def user_input STDIN.gets.chomp end |