galaxy_guide 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.rspec +2 -0
- data/Gemfile +25 -0
- data/Gemfile.lock +79 -0
- data/LICENSE +22 -0
- data/README.md +19 -0
- data/bin/galaxy_guide +4 -0
- data/config/environment.rb +8 -0
- data/lib/cli.rb +77 -0
- data/lib/emoji.rb +104 -0
- data/lib/getweather.rb +25 -0
- data/lib/locator.rb +24 -0
- data/lib/moon_phase.rb +0 -0
- data/lib/pretty-printing.rb +17 -0
- data/lib/quote.rb +23 -0
- data/lib/test.rb +18 -0
- data/lib/weather_codes.rb +54 -0
- data/spec/cli_spec.rb +7 -0
- data/spec/locator_spec.rb +12 -0
- data/spec/pretty_printing_spec.rb +12 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/weather_spec.rb +28 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef9d2ed8c7896f72e04dd4cb8b7e227e873bfc2e
|
4
|
+
data.tar.gz: a1e49cdad4760986be93f506eecd4e2b83c5aa4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ce7be09db10c70f91f6c7fe2b54bc6fda75f4854d658074df15a7ed56647f9c337792d56e99ed953c140e09cc6b3c79c168146c5f33775dcfb2f8e722039acca
|
7
|
+
data.tar.gz: 178a281b33aba7e228082251cf8d1524c5fdf1b9a7f5c3b22beae257b4c710c7ecdf05a483bf3bbde66a4bd1cb82a8e5acc5e3a497b55cb54bc1f87fa137c7a9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rest-client'
|
4
|
+
|
5
|
+
gem 'pry', :group => :development
|
6
|
+
|
7
|
+
gem 'geocoder'
|
8
|
+
|
9
|
+
gem 'json'
|
10
|
+
|
11
|
+
gem 'nokogiri'
|
12
|
+
|
13
|
+
gem 'ermahgerd'
|
14
|
+
|
15
|
+
gem 'talk_like_a_pirate'
|
16
|
+
|
17
|
+
gem 'dogeify'
|
18
|
+
|
19
|
+
gem 'igpay_atinlay'
|
20
|
+
|
21
|
+
gem 'rspec', :group => :test
|
22
|
+
|
23
|
+
gem 'simplecov', :require => false, :group => :test
|
24
|
+
|
25
|
+
gemspec :name => 'galaxy_guide'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
galaxy_guide (0.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.0)
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
docile (1.1.5)
|
12
|
+
dogeify (1.1.0)
|
13
|
+
engtagger
|
14
|
+
domain_name (0.5.24)
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
16
|
+
engtagger (0.2.0)
|
17
|
+
ermahgerd (0.0.1)
|
18
|
+
geocoder (1.2.9)
|
19
|
+
http-cookie (1.0.2)
|
20
|
+
domain_name (~> 0.5)
|
21
|
+
igpay_atinlay (1.0)
|
22
|
+
json (1.8.1)
|
23
|
+
method_source (0.8.2)
|
24
|
+
mime-types (2.6.1)
|
25
|
+
mini_portile (0.6.2)
|
26
|
+
netrc (0.10.3)
|
27
|
+
nokogiri (1.6.6.2)
|
28
|
+
mini_portile (~> 0.6.0)
|
29
|
+
pry (0.10.1)
|
30
|
+
coderay (~> 1.1.0)
|
31
|
+
method_source (~> 0.8.1)
|
32
|
+
slop (~> 3.4)
|
33
|
+
rest-client (1.8.0)
|
34
|
+
http-cookie (>= 1.0.2, < 2.0)
|
35
|
+
mime-types (>= 1.16, < 3.0)
|
36
|
+
netrc (~> 0.7)
|
37
|
+
rspec (3.3.0)
|
38
|
+
rspec-core (~> 3.3.0)
|
39
|
+
rspec-expectations (~> 3.3.0)
|
40
|
+
rspec-mocks (~> 3.3.0)
|
41
|
+
rspec-core (3.3.2)
|
42
|
+
rspec-support (~> 3.3.0)
|
43
|
+
rspec-expectations (3.3.1)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.3.0)
|
46
|
+
rspec-mocks (3.3.2)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.3.0)
|
49
|
+
rspec-support (3.3.0)
|
50
|
+
simplecov (0.10.0)
|
51
|
+
docile (~> 1.1.0)
|
52
|
+
json (~> 1.8)
|
53
|
+
simplecov-html (~> 0.10.0)
|
54
|
+
simplecov-html (0.10.0)
|
55
|
+
slop (3.6.0)
|
56
|
+
talk_like_a_pirate (0.1.0)
|
57
|
+
unf (0.1.4)
|
58
|
+
unf_ext
|
59
|
+
unf_ext (0.0.7.1)
|
60
|
+
|
61
|
+
PLATFORMS
|
62
|
+
ruby
|
63
|
+
|
64
|
+
DEPENDENCIES
|
65
|
+
dogeify
|
66
|
+
ermahgerd
|
67
|
+
galaxy_guide!
|
68
|
+
geocoder
|
69
|
+
igpay_atinlay
|
70
|
+
json
|
71
|
+
nokogiri
|
72
|
+
pry
|
73
|
+
rest-client
|
74
|
+
rspec
|
75
|
+
simplecov
|
76
|
+
talk_like_a_pirate
|
77
|
+
|
78
|
+
BUNDLED WITH
|
79
|
+
1.10.6
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Jessica Wray
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
## Flatiron's Guide to the Galaxy
|
2
|
+
|
3
|
+
A 'Hitchhiker's Guide' -themed command line interface with a dashboard (location, weather, and randomly generated Douglas Adams quote) that the user can view in a variety of intergalactic languages.
|
4
|
+
|
5
|
+
Uses the [Dogeify](https://github.com/mhuggins/dogeify), [Igpay Atinlay](https://rubygems.org/gems/igpay_atinlay/versions/1.0), [Talk Like A Pirate](https://github.com/stevehodges/talk_like_a_pirate), [Ermahgerd](https://github.com/danbernier/ermahgerd), [Nokogiri](https://github.com/sparklemotion/nokogiri), [Geocoder](https://github.com/alexreisner/geocoder) and [RestClient](https://github.com/rest-client/rest-client) gems, and the [OpenWeatherMap API](http://api.openweathermap.org).
|
6
|
+
|
7
|
+
While the dashboard comes supplied with sample content, we provide a very basic emoji language so that even the emoji option supports dynamic content!
|
8
|
+
|
9
|
+
In v2.0 we hope to include Vogon.
|
10
|
+
|
11
|
+
### Running the CLI
|
12
|
+
|
13
|
+
You'll need to obtain your own API key from Open Weather -- it's easy and free -- and put it in your own key.rb file in the root directory. The file will look like
|
14
|
+
|
15
|
+
WEATHER_KEY = "yourAPIkeyhere"
|
16
|
+
|
17
|
+
Then when you install the gem, you can run it from the command line by typing "galaxy_guide".
|
18
|
+
|
19
|
+
That's it!
|
data/bin/galaxy_guide
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require_relative '../lib/locator.rb'
|
2
|
+
require_relative '../lib/getweather.rb'
|
3
|
+
require_relative '../key.rb'
|
4
|
+
require_relative '../lib/cli.rb'
|
5
|
+
require_relative '../lib/weather_codes.rb'
|
6
|
+
require_relative '../lib/quote.rb'
|
7
|
+
require_relative '../lib/emoji.rb'
|
8
|
+
require_relative '../lib/pretty-printing.rb'
|
data/lib/cli.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'dogeify/all'
|
2
|
+
require 'Ermahgerd'
|
3
|
+
require 'talk_like_a_pirate'
|
4
|
+
require 'igpay_atinlay'
|
5
|
+
|
6
|
+
class CLI
|
7
|
+
|
8
|
+
def reset_content
|
9
|
+
@content = "Welcome to the Flatiron Guide to the Galaxy! Remember: DON'T PANIC. Looks like you've ended up on Earth in #{@weather[:city]}. Too bad about its imminent destruction. #{GREETINGS[@weather[:id].to_s[0]]}! It's #{@weather[:temp].to_i} degrees with #{CODES[@weather[:id].to_s]}. And don't forget your towel."
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@zip = Location.new.zip
|
14
|
+
@weather = WeatherAPI.new(@zip).returnhash
|
15
|
+
@mode = 'english'
|
16
|
+
@content = mode_toggle
|
17
|
+
@allowable = ['english', 'doge', 'ermahgerd', 'ermagerd', 'pirate', 'pig latin', 'emoji', 'exit']
|
18
|
+
@menu = "No matter where you travel in the galaxy, we have you covered: no Babel Fish required. Would you like to view content in English, Emoji, Ermahgerd, Pirate, Pig Latin, or Doge? You can type Exit to exit at any time."
|
19
|
+
display
|
20
|
+
end
|
21
|
+
|
22
|
+
def quote
|
23
|
+
"\n#{format(QUOTE_ARRAY[rand(QUOTE_ARRAY.size)])} - Douglas Adams\n"
|
24
|
+
end
|
25
|
+
|
26
|
+
def display
|
27
|
+
while @mode != 'exit'
|
28
|
+
content
|
29
|
+
menu
|
30
|
+
mode_toggle
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def mode_toggle
|
35
|
+
if @mode == 'english'
|
36
|
+
@content = format(reset_content)
|
37
|
+
elsif @mode == 'doge'
|
38
|
+
@content = format(reset_content.dogeify)
|
39
|
+
elsif @mode == 'ermahgerd' || @mode == 'ermagerd'
|
40
|
+
@content = format(Ermahgerd.translate(reset_content))
|
41
|
+
elsif @mode == 'pirate'
|
42
|
+
@content = format(TalkLikeAPirate.translate(reset_content))
|
43
|
+
elsif @mode == 'pig latin'
|
44
|
+
@content = format(reset_content.to_pig_latin)
|
45
|
+
elsif @mode == 'emoji'
|
46
|
+
@content = Emojify.new(@weather[:city], @weather[:id].to_s[0], @weather[:temp].to_i.to_s, CODES[@weather[:id].to_s]).output
|
47
|
+
elsif !@allowable.include?(@mode)
|
48
|
+
menu("I'm sorry, I didn't understand that. Would you like to view content in English, Emoji, Ermahgerd, Pirate, Pig Latin, or Doge? You can type Exit to exit at any time.")
|
49
|
+
mode_toggle
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def content
|
54
|
+
[divider, @content, quote, divider].each do |thing|
|
55
|
+
puts thing
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def divider
|
60
|
+
"\n ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
def menu(text = @menu)
|
64
|
+
menu = [divider,
|
65
|
+
format(text),
|
66
|
+
divider]
|
67
|
+
menu.each do |thing|
|
68
|
+
puts thing
|
69
|
+
end
|
70
|
+
@mode = gets.chomp.downcase
|
71
|
+
end
|
72
|
+
|
73
|
+
def format(text)
|
74
|
+
pp = PrettyPrint.new(text,10)
|
75
|
+
prettytext = pp.format
|
76
|
+
end
|
77
|
+
end
|
data/lib/emoji.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'pry'
|
2
|
+
class Emojify
|
3
|
+
|
4
|
+
def initialize(city,weather_greeting,temp,weather_code)
|
5
|
+
@translations = {
|
6
|
+
cities:{
|
7
|
+
"new york"=>"🇺🇸 🗽",
|
8
|
+
"los angeles"=>"🇺🇸 🌊 🌴",
|
9
|
+
"san francisco"=>"🇺🇸 🌁",
|
10
|
+
"other"=>"🇺🇸"
|
11
|
+
},
|
12
|
+
greetings:{
|
13
|
+
"2"=>"‼️ 🔌 💥",
|
14
|
+
"3"=>"💦 💦 💦",
|
15
|
+
"5"=>"💦 💦 💦",
|
16
|
+
"6"=>"⛄️ ⁉️",
|
17
|
+
"7"=>"🌀 💨 👒",
|
18
|
+
"8"=>"😎 🌞 👍",
|
19
|
+
"9"=>"🌋 💦 🔥 ✨"
|
20
|
+
},
|
21
|
+
temps:{
|
22
|
+
"1"=>"1️⃣",
|
23
|
+
"2"=>"2️⃣",
|
24
|
+
"3"=>"3️⃣",
|
25
|
+
"4"=>"4️⃣",
|
26
|
+
"5"=>"5️⃣",
|
27
|
+
"6"=>"6️⃣",
|
28
|
+
"7"=>"7️⃣",
|
29
|
+
"8"=>"8️⃣",
|
30
|
+
"9"=>"9️⃣",
|
31
|
+
"0"=>"0️⃣"
|
32
|
+
},
|
33
|
+
codes:{
|
34
|
+
"thunderstorm"=>"⚡️ 💦",
|
35
|
+
"rain"=>"☔️",
|
36
|
+
"drizzle"=>"💦 💧",
|
37
|
+
"snow"=>"❄️",
|
38
|
+
"overcast clouds"=>"☁️",
|
39
|
+
"clear sky"=>"☀️",
|
40
|
+
"clouds"=>"⛅️",
|
41
|
+
"breeze"=>"💨",
|
42
|
+
"windy"=>"💨 💨 💨"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
@city = city
|
46
|
+
@greeting = weather_greeting
|
47
|
+
@temp = temp
|
48
|
+
@code = weather_code
|
49
|
+
end
|
50
|
+
|
51
|
+
def translate_city
|
52
|
+
if !@translations[:cities].keys.include? @city.downcase
|
53
|
+
@city = @translations[:cities]["other"]
|
54
|
+
else
|
55
|
+
@city = @translations[:cities][@city.downcase]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def translate_greeting
|
60
|
+
@greeting = @translations[:greetings][@greeting]
|
61
|
+
end
|
62
|
+
|
63
|
+
def translate_temp
|
64
|
+
t = []
|
65
|
+
@temp.split("").each do |num|
|
66
|
+
t << @translations[:temps][num]
|
67
|
+
end
|
68
|
+
@temp = t.join(" ")
|
69
|
+
end
|
70
|
+
|
71
|
+
def translate_weather
|
72
|
+
c = []
|
73
|
+
@translations[:codes].each do |key, val|
|
74
|
+
if @code.include? key
|
75
|
+
c << val
|
76
|
+
end
|
77
|
+
end
|
78
|
+
@code = c.join(" ")
|
79
|
+
end
|
80
|
+
|
81
|
+
def output
|
82
|
+
output =
|
83
|
+
" 👋 😄 👍 📜 🌟 🌠 ✨ 💫
|
84
|
+
‼️ 🚫 😖 ‼️ 🆗
|
85
|
+
🌍 🌎 🌏 📍 #{translate_city}
|
86
|
+
😲 👎 💥 🔫 💣 🔚 🔜
|
87
|
+
#{translate_greeting} #{translate_temp} 🌀 ➕ #{translate_weather}
|
88
|
+
🔮 💈 💸 💿 🚨 🎠 🎲 💃 ✨ 🍻 🍥 🐶
|
89
|
+
"
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
# e = Emojify.new("New York", "9", "30","clouds")
|
94
|
+
# puts e.output
|
95
|
+
|
96
|
+
# GREETINGS = {
|
97
|
+
# "2" => "Be careful of lightning",
|
98
|
+
# "3" => "Grab an umbrella",
|
99
|
+
# "5" => "Put on some rain boots",
|
100
|
+
# "6" => "Put on some warm socks",
|
101
|
+
# "7" => "Stay dry",
|
102
|
+
# "8" => "What a lovely day though",
|
103
|
+
# "9" => "Hold on to your hat"
|
104
|
+
# }
|
data/lib/getweather.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
class WeatherAPI
|
4
|
+
attr_accessor :zip, :info
|
5
|
+
def initialize(zip)
|
6
|
+
@zip = zip.to_i
|
7
|
+
@url = "http://api.openweathermap.org/data/2.5/weather?zip=#{@zip},us&units=imperial&APPID=#{WEATHER_KEY}"
|
8
|
+
@info = {}
|
9
|
+
apicall
|
10
|
+
end
|
11
|
+
|
12
|
+
def apicall
|
13
|
+
openweather_json = RestClient.get(@url)
|
14
|
+
@parsed = JSON.parse(openweather_json)
|
15
|
+
rescue
|
16
|
+
"bad link"
|
17
|
+
end
|
18
|
+
|
19
|
+
def returnhash
|
20
|
+
@info[:city] = @parsed["name"]
|
21
|
+
@info[:id] = @parsed["weather"][0]["id"]
|
22
|
+
@info[:temp] = @parsed["main"]["temp"]
|
23
|
+
@info
|
24
|
+
end
|
25
|
+
end
|
data/lib/locator.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
require 'Nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'geocoder'
|
5
|
+
|
6
|
+
class Location
|
7
|
+
attr_accessor :ip, :zip
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@ip = get_ip
|
11
|
+
@zip = get_zip
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_ip
|
15
|
+
html = open('http://ipecho.net/')
|
16
|
+
noko = Nokogiri::HTML(html)
|
17
|
+
noko.search('h1').text.gsub("Your IP is ", "")
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_zip
|
21
|
+
Geocoder.search(@ip)[0].data["zip_code"]
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/lib/moon_phase.rb
ADDED
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class PrettyPrint
|
2
|
+
def initialize(quote,length)
|
3
|
+
@quote = quote
|
4
|
+
@length = length
|
5
|
+
@arr = @quote.split(" ")
|
6
|
+
end
|
7
|
+
|
8
|
+
def format
|
9
|
+
q = []
|
10
|
+
i = 0
|
11
|
+
while i < @arr.length
|
12
|
+
q << " | #{@arr[i..i+@length].join(" ")}"
|
13
|
+
i += @length+1
|
14
|
+
end
|
15
|
+
@quote = q.join("\n")
|
16
|
+
end
|
17
|
+
end
|
data/lib/quote.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
quotearray = ["Flying is learning how to throw yourself at the ground and miss.",
|
2
|
+
"If it looks like a duck, and quacks like a duck, we have at least to consider the possibility that we have a small aquatic bird of the family anatidae on our hands.",
|
3
|
+
"I love deadlines. I like the whooshing sound they make as they fly by.",
|
4
|
+
"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.",
|
5
|
+
"Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.",
|
6
|
+
"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at and repair.",
|
7
|
+
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move.",
|
8
|
+
"There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable. There is another theory which states that this has already happened.",
|
9
|
+
"He was a dreamer, a thinker, a speculative philosopher... or, as his wife would have it, an idiot.",
|
10
|
+
"The impossible often has a kind of integrity which the merely improbable lacks.",
|
11
|
+
"It is a well-known fact that those people who must want to rule people are, ipso facto, those least suited to do it... anyone who is capable of getting themselves made President should on no account be allowed to do the job.",
|
12
|
+
"Isn't it enough to see that a garden is beautiful without having to believe that there are fairies at the bottom of it too?",
|
13
|
+
"This must be Thursday. I never could get the hang of Thursdays.",
|
14
|
+
"I may not have gone where I intended to go, but I think I have ended up where I intended to be.",
|
15
|
+
"The knack of flying is learning how to throw yourself at the ground and miss.",
|
16
|
+
"Time is an illusion. Lunchtime doubly so.",
|
17
|
+
"Space is big. You just won't believe how vastly, hugely, mind-bogglingly big it is. I mean, you may think it's a long way down the road to the drug store, but that's just peanuts to space.",
|
18
|
+
"We have normality. I repeat, we have normality. Anything you still can't cope with is therefore your own problem.",
|
19
|
+
"For a moment, nothing happened. Then, after a second or so, nothing continued to happen."]
|
20
|
+
i = 0
|
21
|
+
QUOTE_ARRAY = quotearray.map do |quote|
|
22
|
+
"\"#{quote}\""
|
23
|
+
end
|
data/lib/test.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
require 'Nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
class Location
|
6
|
+
attr_accessor :ip, :zip
|
7
|
+
|
8
|
+
def get_ip
|
9
|
+
html = open('http://ipecho.net/')
|
10
|
+
noko = Nokogiri::HTML(html)
|
11
|
+
@ip = noko.search('h1').text.gsub("Your IP is ", "")
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_zip
|
15
|
+
@zip = Geocoder.search(@ip)[0].data["zip_code"]
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require_relative "../config/environment.rb"
|
2
|
+
require 'pry'
|
3
|
+
|
4
|
+
|
5
|
+
CODES = {"200"=>"thunderstorm with light rain", "201"=>"thunderstorm with rain",
|
6
|
+
"202"=>"thunderstorm with heavy rain", "210"=>"light thunderstorm",
|
7
|
+
"211"=>"thunderstorm", "212"=>"heavy thunderstorm", "221"=>"ragged thunderstorm",
|
8
|
+
"230"=>"thunderstorm with light drizzle", "231"=>"thunderstorm with drizzle",
|
9
|
+
"232"=>"thunderstorm with heavy drizzle", "300"=>"light intensity drizzle",
|
10
|
+
"301"=>"drizzle", "302"=>"heavy intensity drizzle", "310"=>"light intensity drizzle rain",
|
11
|
+
"311"=>"drizzle rain", "312"=>"heavy intensity drizzle rain",
|
12
|
+
"313"=>"shower rain and drizzle", "314"=>"heavy shower rain and drizzle",
|
13
|
+
"321"=>"shower drizzle", "500"=>"light rain", "501"=>"moderate rain",
|
14
|
+
"502"=>"heavy intensity rain", "503"=>"very heavy rain", "504"=>"extreme rain",
|
15
|
+
"511"=>"freezing raiw", "520"=>"light intensity shower rain", "521"=>"shower rain",
|
16
|
+
"522"=>"heavy intensity shower rain", "531"=>"ragged shower rain", "600"=>"light snow",
|
17
|
+
"601"=>"snow", "602"=>"heavy snow", "611"=>"sleet", "612"=>"shower sleet",
|
18
|
+
"615"=>"light rain and snow", "616"=>"rain and snow", "620"=>"light shower snow",
|
19
|
+
"621"=>"shower snow", "622"=>"heavy shower snow", "701"=>"mist", "711"=>"smoke",
|
20
|
+
"721"=>"haze", "731"=>"sand, dust whirls", "741"=>"fog", "751"=>"sand", "761"=>"dust",
|
21
|
+
"762"=>"volcanic ash", "771"=>"squalls", "781"=>"tornado", "800"=>"clear sky", "801"=>"few clouds",
|
22
|
+
"802"=>"scattered clouds", "803"=>"broken clouds", "804"=>"overcast clouds", "900"=>"tornado",
|
23
|
+
"901"=>"tropical storm", "902"=>"hurricane", "903"=>"cold", "904"=>"hot", "905"=>"windy", "906"=>"hail",
|
24
|
+
"951"=>"calm", "952"=>"light breeze", "953"=>"gentle breeze", "954"=>"moderate breeze", "955"=>"fresh breeze",
|
25
|
+
"956"=>"strong breeze", "957"=>"high wind, near gale", "958"=>"gale", "959"=>"severe gale", "960"=>"storm",
|
26
|
+
"961"=>"violent storm", "962"=>"hurricane"}
|
27
|
+
|
28
|
+
# CONTENT = "Welcome to the Magic Dashboard. Locating your portal with witchcraft ... \nIt's a big universe, and I'm sorry to tell you that
|
29
|
+
# you've ended up in #{@weather[:city]}.
|
30
|
+
# #{GREETINGS[@weather[:id].to_s[0]]}! It's #{@weather[:temp].to_i} degrees with #{CODES[@weather[:id].to_s]}."
|
31
|
+
|
32
|
+
# CONTENT = "Welcome to the Hitchhiker's Guide to the Galaxy! Remember: DON'T PANIC.\n" +
|
33
|
+
# "Looks like you've ended up on Earth in #{@weather[:city]}. Sorry about the imminent destruction of your planet.\n
|
34
|
+
# #{GREETINGS[@weather[:id].to_s[0]]}! It's #{@weather[:temp].to_i} degrees with #{CODES[@weather[:id].to_s]}."
|
35
|
+
|
36
|
+
# code_meanings = {
|
37
|
+
# "2" => "thunderstorm",
|
38
|
+
# "3" => "drizzle",
|
39
|
+
# "5" => "rain",
|
40
|
+
# "6" => "snow",
|
41
|
+
# "7" => "atomsphere",
|
42
|
+
# "8" => "clouds",
|
43
|
+
# "9" => "additional"
|
44
|
+
# }
|
45
|
+
|
46
|
+
GREETINGS = {
|
47
|
+
"2" => "Be careful of lightning",
|
48
|
+
"3" => "Grab an umbrella",
|
49
|
+
"5" => "Put on some rain boots",
|
50
|
+
"6" => "Put on some warm socks",
|
51
|
+
"7" => "Stay dry",
|
52
|
+
"8" => "What a lovely day though",
|
53
|
+
"9" => "Hold on to your hat"
|
54
|
+
}
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/locator.rb'
|
3
|
+
|
4
|
+
describe 'Location getter' do
|
5
|
+
loc = Location.new
|
6
|
+
it 'gets ip correctly' do
|
7
|
+
expect(loc.ip).to eq('71.183.42.152')
|
8
|
+
end
|
9
|
+
it 'gets zipcode correctly' do
|
10
|
+
expect(loc.zip).to eq('10006')
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Pretty Printer' do
|
4
|
+
it 'takes a quote and length on initialization' do
|
5
|
+
expect{ PrettyPrint.new }.to raise_error(ArgumentError)
|
6
|
+
end
|
7
|
+
it 'pretty prints correctly' do
|
8
|
+
quote = "If it looks like a duck, and quacks like a duck, we have at least to consider the possibility that we have a small aquatic bird of the family anatidae on our hands."
|
9
|
+
pp = PrettyPrint.new(quote,10)
|
10
|
+
expect(pp.format).to include('|')
|
11
|
+
end
|
12
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "WeatherAPI" do
|
4
|
+
|
5
|
+
describe "WeatherAPI - ::new" do
|
6
|
+
it 'takes a zip code on initialization' do
|
7
|
+
weather = WeatherAPI.new("90266")
|
8
|
+
expect(weather.zip).to eq(90266)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
describe "WeatherAPI - ::apicall" do
|
12
|
+
it 'parses the url correctly' do
|
13
|
+
expect(RestClient).to receive(:get).and_raise(RestClient::ResourceNotFound)
|
14
|
+
# expect(RestClient).to receive(:get).and_return("")
|
15
|
+
WeatherAPI.new("90210")
|
16
|
+
end
|
17
|
+
it 'updates the weather if it changes' do
|
18
|
+
dummy_data = %{
|
19
|
+
{"coord":{"lon":-73.97,"lat":40.78},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"base":"cmc stations","main":{"temp":82.56,"pressure":1011,"humidity":39,"temp_min":78.8,"temp_max":86},"wind":{"speed":11.02,"deg":300},"clouds":{"all":40},"dt":1439405431,"sys":{"type":1,"id":2120,"message":0.0458,"country":"US","sunrise":1439373817,"sunset":1439423838},"id":5125771,"name":"Manhattan","cod":200}
|
20
|
+
}
|
21
|
+
expect(RestClient).to receive(:get).and_return(dummy_data)
|
22
|
+
weather_api = WeatherAPI.new("10001")
|
23
|
+
expect(weather_api.returnhash[:city]).to eq("Manhattan")
|
24
|
+
expect(weather_api.returnhash[:id]).to eq(802)
|
25
|
+
expect(weather_api.returnhash[:temp]).to eq(82.56)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: galaxy_guide
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zoe Chodosh, Jessica Wray
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A weather and location enabled CLI dashboard with silly language options.
|
14
|
+
email: jessica.wray@gmail.com, zchodosh@gmail.com
|
15
|
+
executables:
|
16
|
+
- galaxy_guide
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- "./lib/emoji.rb"
|
21
|
+
- "./lib/getweather.rb"
|
22
|
+
- "./lib/locator.rb"
|
23
|
+
- "./lib/moon_phase.rb"
|
24
|
+
- "./lib/pretty-printing.rb"
|
25
|
+
- "./lib/quote.rb"
|
26
|
+
- "./lib/test.rb"
|
27
|
+
- "./lib/weather_codes.rb"
|
28
|
+
- "./spec/cli_spec.rb"
|
29
|
+
- "./spec/locator_spec.rb"
|
30
|
+
- "./spec/pretty_printing_spec.rb"
|
31
|
+
- "./spec/spec_helper.rb"
|
32
|
+
- "./spec/weather_spec.rb"
|
33
|
+
- ".gitignore"
|
34
|
+
- ".rspec"
|
35
|
+
- Gemfile
|
36
|
+
- Gemfile.lock
|
37
|
+
- LICENSE
|
38
|
+
- README.md
|
39
|
+
- bin/galaxy_guide
|
40
|
+
- config/environment.rb
|
41
|
+
- lib/cli.rb
|
42
|
+
homepage: http://rubygems.org/gems/galaxy_guide
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.4.8
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Flatiron Guide to the Galaxy!
|
66
|
+
test_files: []
|