space_missions 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +65 -0
- data/Rakefile +6 -0
- data/bin/console +18 -0
- data/bin/setup +8 -0
- data/bin/space_missions +6 -0
- data/history.txt +14 -0
- data/lib/space_missions.rb +9 -0
- data/lib/space_missions/cli.rb +319 -0
- data/lib/space_missions/mission.rb +57 -0
- data/lib/space_missions/scraper.rb +51 -0
- data/lib/space_missions/version.rb +3 -0
- data/notes +120 -0
- data/space_missions-0.1.0.gem +0 -0
- data/space_missions-0.1.2.gem +0 -0
- data/space_missions-0.1.3.gem +0 -0
- data/space_missions.gemspec +33 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3e5e6cac63dfd4ebfdbe989214c675d347a2089d
|
4
|
+
data.tar.gz: b09ffc9af24f4a7f769f0bd518a228f5d067d7ab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7fc2c8b2ba4f27dd4c1f0b892c695717b56bdcf873d9076503fec0de09a9bf787fdfc45fee3aee9081460450f171ab77726ddb405e4837d9afca4dd8ef228c05
|
7
|
+
data.tar.gz: c8ddab22260e0c59a9b567389c6b8e72c25ba36b3e3ad3149c753ff19b084f7a39e306db09e60377ff18b3653c7a4ecea4e682b0def7f450830b379f33c9a16a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at joanrigdon@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 joan
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# SpaceMissions
|
2
|
+
|
3
|
+
Welcome to SpaceMissions gem! This gem scrapes the NASA JPL (National Aeronautics and Space Administration, Jet Propulsion Laboratory) site that lists its missions, past, present and future!
|
4
|
+
|
5
|
+
You can use this gem to see a list of missions, pick any mission for more information, or search missions by target, description, status or launch date.
|
6
|
+
|
7
|
+
There's a lot of space exploration going on out there. Enjoy yourself!
|
8
|
+
|
9
|
+
Here is a map of how the code flows:
|
10
|
+
https://www.draw.io/#G1kTJV3IdZMrHr_OBRAEg7t85lNHmaL0l8
|
11
|
+
|
12
|
+
|
13
|
+
Here are some blog posts I wrote about building this project:
|
14
|
+
|
15
|
+
Blog post: Flatiron Week 4: creating my own Ruby gem: a tale of fear and Git
|
16
|
+
https://medium.com/me/stats/post/a0103dc6a6e7
|
17
|
+
|
18
|
+
Blog post: CLI Gem Part Two: Scope and Flow!
|
19
|
+
https://medium.com/p/5a56b6190fa7/edit
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
Possible future features:
|
24
|
+
-refine secondary search results
|
25
|
+
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
Add this line to your application's Gemfile:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem 'space_missions'
|
33
|
+
```
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
$ bundle
|
38
|
+
|
39
|
+
Or install it yourself as:
|
40
|
+
|
41
|
+
$ gem install space_missions
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Once installed, you can run the gem with: ./bin/space_missions
|
46
|
+
You will be presented with a list of current JPL space missions and instructions on how to proceed.
|
47
|
+
Have fun checking JPL's many ongoing missions!
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/space_missions. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
62
|
+
|
63
|
+
## Code of Conduct
|
64
|
+
|
65
|
+
Everyone interacting in the SpaceMissions project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/space_missions/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative "../lib/space_missions"
|
4
|
+
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
def reload!
|
14
|
+
load './lib/space_missions/cli.rb'
|
15
|
+
end
|
16
|
+
|
17
|
+
require "irb"
|
18
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bin/space_missions
ADDED
data/history.txt
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
=== 0.1.1 - 3/17/19
|
2
|
+
|
3
|
+
* 1 Bug Fix
|
4
|
+
- fixed 'before' search. previous version tried to account for launch dates of 'TBD' but broke functionality.
|
5
|
+
|
6
|
+
=== 0.1.3
|
7
|
+
Bug Fix
|
8
|
+
- fixed 'between' search
|
9
|
+
|
10
|
+
==0.1.4
|
11
|
+
|
12
|
+
Feature
|
13
|
+
-added ability to search all missions, not just past, current, proposed, future
|
14
|
+
-added ability to sort missions by year
|
@@ -0,0 +1,319 @@
|
|
1
|
+
class SpaceMissions::CLI
|
2
|
+
attr_accessor :target, :list, :missions_by_target
|
3
|
+
|
4
|
+
|
5
|
+
def call
|
6
|
+
#self
|
7
|
+
welcome
|
8
|
+
get_data
|
9
|
+
new_search#=> pick by status => display missions => refine search => listen
|
10
|
+
end
|
11
|
+
|
12
|
+
def welcome
|
13
|
+
3.times do |x|
|
14
|
+
puts"".center(80).on_white
|
15
|
+
end
|
16
|
+
puts"*************************************".center(80).black.on_white
|
17
|
+
puts "Welcome to JPL's Space Missions!".center(80).black.on_white
|
18
|
+
puts"*************************************".center(80).black.on_white
|
19
|
+
puts"".center(80).black.on_white
|
20
|
+
puts"".center(80).black.on_white
|
21
|
+
puts"This Ruby Gem is based on data from NASA's Jet Propulsion Laboratory.".center(80).black.on_white
|
22
|
+
puts"JPL, based in Los Angeles is one of NASA's three space flight centers.".center(80).black.on_white
|
23
|
+
puts"Welcome to your universe!".center(80).black.on_white
|
24
|
+
3.times do |x|
|
25
|
+
puts"".center(80).on_white
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_data
|
30
|
+
SpaceMissions::Scraper.new.get_mission_links
|
31
|
+
puts "\n... Hang on, we're getting data from #{SpaceMissions::Mission.all.size} missions for you!"
|
32
|
+
sleep(2)
|
33
|
+
puts "Give us just a few more seconds to search the universe ..."
|
34
|
+
puts ""
|
35
|
+
sleep(2)
|
36
|
+
puts "It's a big universe ..."
|
37
|
+
puts ""
|
38
|
+
puts "Did you know ... "
|
39
|
+
puts "that JPL's roots go back to 1936?"
|
40
|
+
puts "That's when a group of researchers at Caltech's Guggenheim Aeronautical Laboratory performed a series of rocket experiments in a dry canyon wash known as Arroyo Seco. They moved out to the valley after an accidental explosion on campus..."
|
41
|
+
puts ""
|
42
|
+
sleep (2)
|
43
|
+
puts "JPL has two current missions that launched in 1977. They are the twin Voyager probes. Both have reached interstellar space, which means they are beyond the magnetic field of our sun. You can learn more about them under 'current' missions ..."
|
44
|
+
SpaceMissions::Scraper.new.get_attributes
|
45
|
+
end
|
46
|
+
|
47
|
+
#******************* get/list missions methods ***************
|
48
|
+
|
49
|
+
def new_search
|
50
|
+
puts ""
|
51
|
+
puts "Which set of JPL's missions would you like to explore?"
|
52
|
+
puts "Try one of these:"
|
53
|
+
puts ""
|
54
|
+
puts "Past"
|
55
|
+
puts "Current"
|
56
|
+
puts "Future"
|
57
|
+
puts "Proposed"
|
58
|
+
puts "All"
|
59
|
+
puts ""
|
60
|
+
puts "You can also type 'exit' to quit."
|
61
|
+
puts ""
|
62
|
+
input = nil
|
63
|
+
while input != "exit"
|
64
|
+
input = gets.strip.downcase
|
65
|
+
if ["past", "current", "future", "proposed", "all"].include?(input)
|
66
|
+
list = SpaceMissions::Mission.send("find_by_status", input)#do the search
|
67
|
+
display_missions(list) #display results
|
68
|
+
refine_search?# offer 2 options to proceed
|
69
|
+
elsif input == 'exit'
|
70
|
+
goodbye
|
71
|
+
else
|
72
|
+
error
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def display_missions(list)
|
78
|
+
@list = list
|
79
|
+
@list.each.with_index(1) do |mission, index|
|
80
|
+
if mission.acronym == nil
|
81
|
+
puts "#{index}. #{mission.name}".colorize(:blue)
|
82
|
+
else
|
83
|
+
puts "#{index}. #{mission.acronym} - #{mission.name}".colorize(:blue)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def get_mission(input)
|
89
|
+
if input.to_i > 0 && input.to_i <= @list.size
|
90
|
+
mission = @list[input.to_i - 1]
|
91
|
+
if mission
|
92
|
+
show_info(mission)
|
93
|
+
else
|
94
|
+
error
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def show_info(mission)
|
100
|
+
puts ""
|
101
|
+
puts "Fast facts about #{mission.name}:"
|
102
|
+
puts ""
|
103
|
+
puts "Description:".colorize(:blue)
|
104
|
+
puts "#{mission.description}".colorize(:blue)
|
105
|
+
puts ""
|
106
|
+
puts "#{"Acronym:".ljust(20)} => #{mission.acronym}".colorize(:blue) if mission.acronym
|
107
|
+
puts "#{"Status:".ljust(20)} => #{mission.status}".colorize(:blue) if mission.status
|
108
|
+
puts "#{"Type:".ljust(20)} => #{mission.type}".colorize(:blue) if mission.type
|
109
|
+
puts "#{"Launch date:".ljust(20)} => #{mission.launch_date}".colorize(:blue) if mission.launch_date
|
110
|
+
puts "#{"Launch location:".ljust(20)} => #{mission.launch_location}".colorize(:blue) if mission.launch_location
|
111
|
+
puts "#{"End Date:".ljust(20)} => #{mission.landing_date}".colorize(:blue) if mission.landing_date
|
112
|
+
puts "#{"Mission End date:".ljust(20)} => #{mission.mission_end_date}".colorize(:blue) if mission.mission_end_date
|
113
|
+
puts "#{"Target/s:".ljust(20)} => #{mission.targets}".colorize(:blue) if mission.targets
|
114
|
+
puts "#{"Destination/s:".ljust(20)} => #{mission.destinations}".colorize(:blue) if mission.destinations
|
115
|
+
puts "#{"Current location:".ljust(20)} => #{mission.current_location}".colorize(:blue) if mission.current_location
|
116
|
+
puts "#{"Altitude:".ljust(20)} => #{mission.altitude}".colorize(:blue) if mission.altitude
|
117
|
+
puts ""
|
118
|
+
visit_website?(mission)
|
119
|
+
end
|
120
|
+
|
121
|
+
def visit_website?(mission)
|
122
|
+
puts "Would you like to visit this mission\'s website? Type 'Yes' or 'No'"
|
123
|
+
puts ""
|
124
|
+
input = nil
|
125
|
+
while input != "exit"
|
126
|
+
input = gets.strip.downcase
|
127
|
+
if input.downcase == 'yes'
|
128
|
+
mission.open_in_browser
|
129
|
+
search_again?
|
130
|
+
elsif input == 'no'
|
131
|
+
search_again?
|
132
|
+
elsif input == 'exit'
|
133
|
+
goodbye
|
134
|
+
else
|
135
|
+
error
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
#************************* user interface ********************
|
141
|
+
|
142
|
+
def listen(input=nil)
|
143
|
+
while input != "exit"
|
144
|
+
input = gets.strip.downcase
|
145
|
+
get_mission(input)
|
146
|
+
|
147
|
+
case input.downcase
|
148
|
+
when "target"
|
149
|
+
target
|
150
|
+
when "launch"
|
151
|
+
launched_when
|
152
|
+
when "description"
|
153
|
+
description
|
154
|
+
when "new"
|
155
|
+
new_search
|
156
|
+
when "exit"
|
157
|
+
goodbye
|
158
|
+
else
|
159
|
+
error
|
160
|
+
end#case
|
161
|
+
end#while
|
162
|
+
end
|
163
|
+
|
164
|
+
def error
|
165
|
+
puts "Whoa, are you typing in an alien language?"
|
166
|
+
puts "I didn't understand that."
|
167
|
+
puts ""
|
168
|
+
puts "Try your command again."
|
169
|
+
puts "You can also type 'new' for new search or 'exit'."
|
170
|
+
search_again?
|
171
|
+
end
|
172
|
+
|
173
|
+
def search_again?
|
174
|
+
puts ""
|
175
|
+
puts "If you'd like to start a new seach, type 'new'."
|
176
|
+
puts "Or type 'exit' to quit this program'"
|
177
|
+
puts ""
|
178
|
+
listen
|
179
|
+
end
|
180
|
+
|
181
|
+
def refine_search?
|
182
|
+
puts ""
|
183
|
+
puts "If you'd like to refine your search, use one of these commands:"
|
184
|
+
puts ""
|
185
|
+
puts "'target' => search missions by target (planet, universe, etc.)"
|
186
|
+
puts "'launch' => search missions by launch date"
|
187
|
+
puts "'description' => search missions by mission description"
|
188
|
+
puts ""
|
189
|
+
puts "If not, enter the number of any mission you'd like to learn more about."
|
190
|
+
listen
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
#********search by target or description & helper methods******
|
195
|
+
|
196
|
+
def target
|
197
|
+
puts ""
|
198
|
+
puts "For a list of missions by target, enter target:"
|
199
|
+
puts "Examples: 'Earth,' 'Mars', 'Universe', 'moon' etc."
|
200
|
+
puts ""
|
201
|
+
process_input("find_by_target")
|
202
|
+
end
|
203
|
+
|
204
|
+
def description
|
205
|
+
puts ""
|
206
|
+
puts "To search missions by their descriptions, enter a word or phrase."
|
207
|
+
puts "Examples: 'rover,' 'spectrometer', 'climate', etc."
|
208
|
+
puts ""
|
209
|
+
process_input("find_by_description")
|
210
|
+
end
|
211
|
+
|
212
|
+
def process_input(method)
|
213
|
+
input = nil
|
214
|
+
while input != "exit"
|
215
|
+
input = gets.strip
|
216
|
+
@list = SpaceMissions::Mission.send(method, input)
|
217
|
+
refined_search_results
|
218
|
+
end#while
|
219
|
+
end
|
220
|
+
|
221
|
+
def refined_search_results
|
222
|
+
if @list == []
|
223
|
+
puts ""
|
224
|
+
puts "Sorry, we couldn't find any missions matching your search."
|
225
|
+
puts ""
|
226
|
+
search_again?
|
227
|
+
else
|
228
|
+
@list = list
|
229
|
+
display_missions(list)
|
230
|
+
puts ""
|
231
|
+
puts "Please enter the number of a mission you'd like to learn more about."
|
232
|
+
puts "You can also type exit or 'new' to start a new search."
|
233
|
+
puts ""
|
234
|
+
listen
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
#********** search by launch year & helper methods********
|
239
|
+
|
240
|
+
def launched_when
|
241
|
+
@input = nil
|
242
|
+
while @input != "exit"
|
243
|
+
puts ""
|
244
|
+
puts "Tell us which way you'd like to search:"
|
245
|
+
puts ""
|
246
|
+
puts "Examples:"
|
247
|
+
puts "#{'sort'.ljust(20)} => to see missions listed by launch date (if they have launch dates)"
|
248
|
+
puts ""
|
249
|
+
puts "#{'after 2005'.ljust(20)} => missions launched after Dec. 31, 2004"
|
250
|
+
puts "#{'before 1980'.ljust(20)} => missions launched before Jan. 1, 1981"
|
251
|
+
puts "#{'between'.ljust(20)} => to search missions launched during a range of years"
|
252
|
+
puts ""
|
253
|
+
|
254
|
+
@input = gets.strip.split
|
255
|
+
if ["before", "after", "sort"].include?(@input[0])
|
256
|
+
launched_before_or_after
|
257
|
+
elsif
|
258
|
+
@input[0] == "between"
|
259
|
+
launched_between
|
260
|
+
else
|
261
|
+
error
|
262
|
+
end
|
263
|
+
end#while
|
264
|
+
new_search
|
265
|
+
end
|
266
|
+
|
267
|
+
def launched_before_or_after
|
268
|
+
if @input[0] == "sort"
|
269
|
+
@list = SpaceMissions::Mission.sort_by_launch_date
|
270
|
+
refined_search_results
|
271
|
+
elsif @input[1].to_i > 999 && @input[1].to_i < 9999
|
272
|
+
if ["before", "after"].include?(@input[0].downcase)
|
273
|
+
parameter = @input[0]
|
274
|
+
year = @input[1]
|
275
|
+
@list = SpaceMissions::Mission.launched(parameter, year)
|
276
|
+
refined_search_results
|
277
|
+
else
|
278
|
+
error
|
279
|
+
end
|
280
|
+
end
|
281
|
+
new_search
|
282
|
+
end
|
283
|
+
|
284
|
+
def launched_between
|
285
|
+
if "between" == @input[0].downcase
|
286
|
+
while @input != "exit"
|
287
|
+
puts ""
|
288
|
+
puts "Please enter the range of years you\'d like to search."
|
289
|
+
puts ""
|
290
|
+
puts "Example:"
|
291
|
+
puts "'2004 to 2009' => all missions that launched during the years 2005-2008."
|
292
|
+
puts ""
|
293
|
+
|
294
|
+
years = gets.strip.split("to")
|
295
|
+
start_year = years[0].to_i
|
296
|
+
end_year = years[1].to_i
|
297
|
+
|
298
|
+
if start_year < end_year
|
299
|
+
@list = SpaceMissions::Mission.launched("between", start_year, end_year)
|
300
|
+
refined_search_results
|
301
|
+
else
|
302
|
+
@list = SpaceMissions::Mission.launched("between", start_year, end_year)
|
303
|
+
refined_search_results
|
304
|
+
end
|
305
|
+
goodbye if @input == exit
|
306
|
+
end#2nd while
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
#********************************************************
|
311
|
+
|
312
|
+
def goodbye
|
313
|
+
puts "Thanks for visiting! Please come back soon!"
|
314
|
+
exit
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class SpaceMissions::Mission
|
2
|
+
attr_accessor :acronym, :altitude, :attributes, :current_location, :description, :destinations, :end_date, :info, :landing_date, :launch_date, :launch_location, :launch_year, :mission_end_date, :missions_by_status, :name, :number, :status, :targets, :type, :url
|
3
|
+
|
4
|
+
@@all = [] #all missions
|
5
|
+
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@@all << self
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def self.find_by_target(input)
|
13
|
+
missions = @missions_by_status.select {|mission| mission.targets.include?(input.capitalize) if mission.targets}
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find_by_description(input)
|
17
|
+
missions = @missions_by_status.select {|mission| mission.description.downcase.include?(input.downcase) if mission.description}
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find_by_status(input)
|
21
|
+
if input.downcase == "all"
|
22
|
+
@missions_by_status = @@all
|
23
|
+
else
|
24
|
+
@missions_by_status = @@all.select {|mission| mission.status == input.capitalize if mission.status}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.sort_by_launch_date
|
29
|
+
filtered = @missions_by_status.select {|mission| mission.launch_date.scan(/\d{4}/)[0].to_i > 0}
|
30
|
+
missions = filtered.sort_by {|mission| mission.launch_date.scan(/\d{4}/)[0].to_i}
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.launched(parameter, year, end_year=nil)
|
34
|
+
if parameter == "after"
|
35
|
+
missions = @missions_by_status.select {|mission| mission.launch_date.scan(/\d{4}/)[0].to_i > year.to_i}
|
36
|
+
|
37
|
+
elsif parameter == "before"
|
38
|
+
#does not catch launch_date TBD
|
39
|
+
@missions_by_status.select {|mission| mission.launch_date.scan(/\d{4}/)[0].to_i < year.to_i}
|
40
|
+
|
41
|
+
elsif parameter == "between"
|
42
|
+
later = @missions_by_status.select {|mission| mission.launch_date.scan(/\d{4}/)[0].to_i > year}
|
43
|
+
before = @missions_by_status.select {|mission| mission.launch_date.scan(/\d{4}/)[0].to_i < end_year}
|
44
|
+
missions = before & later
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def open_in_browser
|
49
|
+
system("open '#{url}'")
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.all
|
53
|
+
@@all
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class SpaceMissions::Scraper
|
2
|
+
attr_accessor :value, :key, :kv
|
3
|
+
|
4
|
+
#scrape main page for mission links, initialize missions
|
5
|
+
def get_mission_links
|
6
|
+
doc = Nokogiri::HTML(open("https://www.jpl.nasa.gov/missions"))
|
7
|
+
#@doc = Nokogiri::HTML(open("https://www.jpl.nasa.gov/missions/?type=current"))
|
8
|
+
slides = doc.css('ul.articles li.slide')
|
9
|
+
slides.each do |slide|
|
10
|
+
mission = SpaceMissions::Mission.new
|
11
|
+
mission.url = slide.css('a').attribute('href').value.gsub("http", "https")
|
12
|
+
mission.description = slide.css('div.item_tease_overlay').text.gsub(/[\r]|[\n]/, "")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#scrape attributes from slide links, add to missions
|
17
|
+
def get_attributes
|
18
|
+
SpaceMissions::Mission.all.each do |mission|
|
19
|
+
doc = Nokogiri::HTML(open(mission.url))
|
20
|
+
mission.name = doc.css('.media_feature_title').text.strip
|
21
|
+
#from fast_facts box
|
22
|
+
attributes = doc.css('ul.fast_facts li')
|
23
|
+
attributes.each do |el|
|
24
|
+
@el = el
|
25
|
+
@kv = el.children.children.text.split(":")
|
26
|
+
@key = @kv[0].downcase.gsub(" ", "_")
|
27
|
+
format_keys_and_values
|
28
|
+
mission.send("#{@key}=", @value)
|
29
|
+
end #second do
|
30
|
+
end #first do
|
31
|
+
end
|
32
|
+
|
33
|
+
#deals with edge cases for both keys and values
|
34
|
+
def format_keys_and_values
|
35
|
+
if @key.include?("date")
|
36
|
+
cal_date = @el.css("p").children[1].text.strip #if @el
|
37
|
+
time = @el.css("p").children[3].text.strip if @el.css("p").children[3]
|
38
|
+
if time
|
39
|
+
@value = "#{cal_date}, #{time}"
|
40
|
+
else
|
41
|
+
@value = "#{cal_date}"
|
42
|
+
end
|
43
|
+
else
|
44
|
+
@value = @kv[1...(@kv.size)].map{|val| val.gsub(/[\r]|[\n]/, "").strip}.join(",")
|
45
|
+
end
|
46
|
+
|
47
|
+
if ["target", "destination"].include?(@key)
|
48
|
+
@key = "#{@key}s"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/notes
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
Notes
|
2
|
+
|
3
|
+
Here is a screencast of me developing a method for searching missions by launch year.
|
4
|
+
https://www.useloom.com/share/caa4d8afc1c2445bacb794a0cdbdd6cb
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
__________________________________________________________________
|
9
|
+
INTERFACE
|
10
|
+
|
11
|
+
user types space-missions - that starts program
|
12
|
+
|
13
|
+
Welcome to Space Missions!
|
14
|
+
|
15
|
+
automatically load a list of NASA JPL's current space missions
|
16
|
+
pick mission
|
17
|
+
type number
|
18
|
+
get full description
|
19
|
+
|
20
|
+
|
21
|
+
extras
|
22
|
+
- done - type in mars return all missions that target mars
|
23
|
+
|
24
|
+
|
25
|
+
__________________________________________________________________
|
26
|
+
|
27
|
+
|
28
|
+
TO DO
|
29
|
+
|
30
|
+
|
31
|
+
--done fix formatting of dates ie "Launch Date: June 20, 200812,46 a.m. PDT (07,46 UTC)"
|
32
|
+
|
33
|
+
[21] pry(SpaceMissions::Scraper)> attributes[2].css("p").children[1].text
|
34
|
+
=> "\n\t\t\t\t\t\t\t\t\t September 05, 1977"
|
35
|
+
[22] pry(SpaceMissions::Scraper)> attributes[2].css("p").children[1].text.strip
|
36
|
+
=> "September 05, 1977"
|
37
|
+
[23] pry(SpaceMissions::Scraper)> attributes[2].css("p").children[2].text.strip
|
38
|
+
|
39
|
+
=> ""
|
40
|
+
[24] pry(SpaceMissions::Scraper)> attributes[2].css("p").children[3].text.strip
|
41
|
+
=> "8:56 a.m. EDT (12:56 UTC)"
|
42
|
+
|
43
|
+
-- removed targets instead, as class was not useful for this app/ get Mission.set_targets working
|
44
|
+
-- done fix CLI so after missions are listed, you have the choice of other commands besides picking a mission number or exiting.
|
45
|
+
|
46
|
+
--------
|
47
|
+
cli mods
|
48
|
+
#### search by
|
49
|
+
def target
|
50
|
+
puts "For a list of missions by target, enter target:"
|
51
|
+
puts "Examples: 'Earth,' 'Mars', 'Universe', 'moon' etc."
|
52
|
+
process_input("find_by_target")
|
53
|
+
end
|
54
|
+
|
55
|
+
def description
|
56
|
+
puts "To search missions by their descriptions, enter a word or phrase."
|
57
|
+
puts "Examples: 'rover,' 'spectrometer', 'climate', etc."
|
58
|
+
process_input("find_by_description")
|
59
|
+
end
|
60
|
+
|
61
|
+
def launched_since
|
62
|
+
puts "Enter a year to search missions that have launched since that year"
|
63
|
+
puts "Example:'1983' will return missions launched after Dec. 31, 1983"
|
64
|
+
input = nil
|
65
|
+
while input != "exit"
|
66
|
+
input = gets.strip
|
67
|
+
if input.to_i > 999 && input.to_i < 9999
|
68
|
+
search_results
|
69
|
+
else
|
70
|
+
puts "That's not a valid year." #figure out how to let them guess again.
|
71
|
+
commands
|
72
|
+
end#1st if
|
73
|
+
end#while
|
74
|
+
end
|
75
|
+
|
76
|
+
#helper methods process_input & search_results
|
77
|
+
def process_input(method)
|
78
|
+
input = nil
|
79
|
+
while input != "exit"
|
80
|
+
input = gets.strip.capitalize
|
81
|
+
@list = SpaceMissions::Mission.send(method, input)
|
82
|
+
search_results
|
83
|
+
end#while
|
84
|
+
end
|
85
|
+
|
86
|
+
def search_results
|
87
|
+
if @list == []
|
88
|
+
puts "\nSorry, we couldn't find any missions matching your search."
|
89
|
+
commands
|
90
|
+
else
|
91
|
+
puts ""
|
92
|
+
display_missions
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
____________________________________________________________
|
98
|
+
|
99
|
+
possible future features:
|
100
|
+
|
101
|
+
sort by launch_year
|
102
|
+
# def self.sort_by_launch_year
|
103
|
+
# @launch_year = self.launch_date.scan(/\d{4}/)[0].to_i
|
104
|
+
# sorted = @@all.sort_by(&:launch_year)
|
105
|
+
# binding.pry
|
106
|
+
# end
|
107
|
+
|
108
|
+
search missions by launch, landing date or type
|
109
|
+
|
110
|
+
add to user_says
|
111
|
+
|
112
|
+
#elsif input == "type"
|
113
|
+
# SpaceMissions::Mission.type
|
114
|
+
|
115
|
+
|
116
|
+
add to mission class:
|
117
|
+
#futre featues
|
118
|
+
# def self.find_by_launch_date(input)
|
119
|
+
# missions = @@all.select {|mission| mission.launch_date.split.last == input}
|
120
|
+
# end
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "space_missions/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "space_missions"
|
8
|
+
spec.version = SpaceMissions::VERSION
|
9
|
+
spec.authors = ["Joan Indiana Lyess"]
|
10
|
+
spec.email = ["joanrigdon@gmail.com"]
|
11
|
+
spec.summary = "Lists and lets user search NASA's Jet Propulsion Laboratory space missions."
|
12
|
+
spec.homepage = "https://github.com/joanrig/space_missions2.0"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
16
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
end
|
18
|
+
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "pry", "~> 0"
|
27
|
+
|
28
|
+
spec.add_dependency "nokogiri", "~> 1.10"
|
29
|
+
spec.add_dependency "colorize", "~> 0.8.0"
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: space_missions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joan Indiana Lyess
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.10'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: colorize
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.8.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.8.0
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- joanrigdon@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- CODE_OF_CONDUCT.md
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- bin/space_missions
|
115
|
+
- history.txt
|
116
|
+
- lib/space_missions.rb
|
117
|
+
- lib/space_missions/cli.rb
|
118
|
+
- lib/space_missions/mission.rb
|
119
|
+
- lib/space_missions/scraper.rb
|
120
|
+
- lib/space_missions/version.rb
|
121
|
+
- notes
|
122
|
+
- space_missions-0.1.0.gem
|
123
|
+
- space_missions-0.1.2.gem
|
124
|
+
- space_missions-0.1.3.gem
|
125
|
+
- space_missions.gemspec
|
126
|
+
homepage: https://github.com/joanrig/space_missions2.0
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.5.2.3
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Lists and lets user search NASA's Jet Propulsion Laboratory space missions.
|
150
|
+
test_files: []
|