hiking_guide 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +51 -0
- data/LICENSE +21 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/hiking-guide +5 -0
- data/bin/setup +8 -0
- data/hiking_guide.gemspec +30 -0
- data/lib/hiking_guide.rb +13 -0
- data/lib/hiking_guide/command_line_interface.rb +161 -0
- data/lib/hiking_guide/scraper.rb +49 -0
- data/lib/hiking_guide/trail.rb +78 -0
- data/lib/hiking_guide/version.rb +3 -0
- data/spec.md +13 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6949725dce17ce498d68c619e13aee0b99fe18a0
|
4
|
+
data.tar.gz: 4dd4df2650aa0da116ae1835213045d4b000b9cd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0713b4756e6e1b7cb35a7fb88053f805168cdb306d92d7d34d59032e0d24981d991084f866a3e2d4545359f5f6cd2d01cb712555b41981ef858c23253d89bfed
|
7
|
+
data.tar.gz: 684a6346be81d48d55ca1934ccea278c6c27d6f338c6b0c71213d9ac36b6985da97c1085f79044310cde61c18b60ff34b1d02459f7a417e17ac6ee261bf9dbbd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at eleanorcjkgraham@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hiking_guide (0.1.0)
|
5
|
+
colorize (~> 0.8, >= 0.8.1)
|
6
|
+
nokogiri (~> 1.6)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
coderay (1.1.1)
|
12
|
+
colorize (0.8.1)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
method_source (0.8.2)
|
15
|
+
mini_portile2 (2.1.0)
|
16
|
+
nokogiri (1.6.8)
|
17
|
+
mini_portile2 (~> 2.1.0)
|
18
|
+
pkg-config (~> 1.1.7)
|
19
|
+
pkg-config (1.1.7)
|
20
|
+
pry (0.10.4)
|
21
|
+
coderay (~> 1.1.0)
|
22
|
+
method_source (~> 0.8.1)
|
23
|
+
slop (~> 3.4)
|
24
|
+
rake (10.4.2)
|
25
|
+
rspec (3.5.0)
|
26
|
+
rspec-core (~> 3.5.0)
|
27
|
+
rspec-expectations (~> 3.5.0)
|
28
|
+
rspec-mocks (~> 3.5.0)
|
29
|
+
rspec-core (3.5.3)
|
30
|
+
rspec-support (~> 3.5.0)
|
31
|
+
rspec-expectations (3.5.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.5.0)
|
34
|
+
rspec-mocks (3.5.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.5.0)
|
37
|
+
rspec-support (3.5.0)
|
38
|
+
slop (3.6.0)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
bundler (~> 1.12)
|
45
|
+
hiking_guide!
|
46
|
+
pry (~> 0.10)
|
47
|
+
rake (~> 10.0)
|
48
|
+
rspec (~> 3.0)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
1.12.5
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Eleanor Graham
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# HikingGuide
|
2
|
+
|
3
|
+
Hiking Guide is a CLI Gem that allows users to browse hiking trails in the US mid-Atlantic region. Following the command-line prompts, users can see trail details and get links to maps of trails in Maryland, Pennsylvania, North Carolina, Virginia, and West Virginia.
|
4
|
+
|
5
|
+
The information in Hiking Guide comes from a volunteer organization called [Hiking Upward](http://www.hikingupward.com/). If you find the information useful, please consider volunteering as a Trail Contributer, or donating to the organization.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'hiking_guide'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install hiking_guide
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Run: ```hiking_guide``` after installing the gem.
|
26
|
+
|
27
|
+
Follow the prompts to browse through lists of hiking trails by state, all from the comfort of your command line.
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
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.
|
32
|
+
|
33
|
+
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).
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/eleanorgraham/hiking_guide. 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.
|
38
|
+
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hiking_guide"
|
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
|
+
require "irb"
|
10
|
+
IRB.start
|
data/bin/hiking-guide
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hiking_guide/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hiking_guide"
|
8
|
+
spec.version = HikingGuide::VERSION
|
9
|
+
spec.authors = ["Eleanor Graham"]
|
10
|
+
spec.email = ["eleanorcjkgraham@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "CLI Gem that shows hiking trails from HikingUpward"
|
13
|
+
spec.description = "Hiking Guide is a CLI Gem that allows users to browse trails in the US mid Atlantic region, taking descriptions from Hiking Upward."
|
14
|
+
spec.homepage = "https://github.com/eleanorgraham/hiking_guide"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = ["hiking-guide"]
|
19
|
+
spec.require_paths = ["lib, lib/hiking_guide"]
|
20
|
+
|
21
|
+
spec.post_install_message = "Thanks for installing! Hit the trails!"
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'nokogiri', '~> 1.6'
|
24
|
+
spec.add_runtime_dependency 'colorize', '~> 0.8', '>= 0.8.1'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
30
|
+
end
|
data/lib/hiking_guide.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'pry'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'colorize'
|
5
|
+
|
6
|
+
require_relative "hiking_guide/version"
|
7
|
+
require_relative "hiking_guide/scraper"
|
8
|
+
require_relative "hiking_guide/trail"
|
9
|
+
require_relative "hiking_guide/command_line_interface"
|
10
|
+
|
11
|
+
|
12
|
+
module HikingGuide
|
13
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
class HikingGuide::CommandLineInteface
|
2
|
+
BASE_PATH = "http://www.hikingupward.com/"
|
3
|
+
|
4
|
+
def self.run
|
5
|
+
greeting
|
6
|
+
main_menu
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.make_trails
|
10
|
+
HikingGuide::Trail.reset_all
|
11
|
+
trails_array = HikingGuide::Scraper.scrape_trail_list(BASE_PATH)
|
12
|
+
HikingGuide::Trail.create_from_collection(trails_array)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.add_trail_attributes
|
16
|
+
HikingGuide::Trail.all.each do |trail|
|
17
|
+
attributes = HikingGuide::Scraper.scrape_trail_profile(trail.profile_url)
|
18
|
+
trail.add_trail_attributes(attributes)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.greeting
|
23
|
+
puts "Setting up your command line trail guide -"
|
24
|
+
puts "Please wait a minute while we gather the trail details..."
|
25
|
+
sleep(1)
|
26
|
+
puts " /\\ ".light_red.on_red
|
27
|
+
puts " / \\ ".light_red.on_red
|
28
|
+
puts " / \\/\\ ".light_red.on_red
|
29
|
+
puts " / / \\ ".light_red.on_red
|
30
|
+
sleep(1)
|
31
|
+
make_trails
|
32
|
+
puts "getting closer..."
|
33
|
+
puts " /\\ ".light_yellow.on_yellow
|
34
|
+
puts " /\\ / \\ ".light_yellow.on_yellow
|
35
|
+
puts " / \\/ \\ ".light_yellow.on_yellow
|
36
|
+
puts " / \\/\\ \\ ".light_yellow.on_yellow
|
37
|
+
puts " / / \\ \\ ".light_yellow.on_yellow
|
38
|
+
puts " / / \\ \\".light_yellow.on_yellow
|
39
|
+
add_trail_attributes
|
40
|
+
puts "All set!"
|
41
|
+
sleep(1)
|
42
|
+
hit_the_trails
|
43
|
+
puts ""
|
44
|
+
puts "Welcome to Hiking Guide!".black.on_green
|
45
|
+
puts ""
|
46
|
+
puts "The information in Hiking Guide comes from a volunteer organization called Hiking Upward (http://www.hikingupward.com/). If you find the information useful, please consider volunteering as a Trail Contributer, or donating to the organization."
|
47
|
+
puts ""
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.hit_the_trails
|
51
|
+
puts " /\\ ".light_green.on_green
|
52
|
+
puts " / \\ ".light_green.on_green
|
53
|
+
puts " / \\ /\\ ".light_green.on_green
|
54
|
+
puts " / \\ / \\ ".light_green.on_green
|
55
|
+
puts " / /\\ / \\ /\\ ".light_green.on_green
|
56
|
+
puts " / / \\ / / \\ ".light_green.on_green
|
57
|
+
puts " / / \\/ /\\/ \\ ".light_green.on_green
|
58
|
+
puts " / / \\ / \\ \\ ".light_green.on_green
|
59
|
+
puts "_______________________________".black.on_green
|
60
|
+
puts "===============================".black.on_green
|
61
|
+
puts " H I T T H E T R A I L S ! ".light_green.on_green
|
62
|
+
puts "===============================".black.on_green
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.main_menu
|
66
|
+
puts "Where would you like to explore?".black.on_green
|
67
|
+
puts "(1) Maryland hikes"
|
68
|
+
puts "(2) Pennsylvania hikes"
|
69
|
+
puts "(3) North Carolina hikes"
|
70
|
+
puts "(4) Virginia hikes"
|
71
|
+
puts "(5) West Virginia hikes"
|
72
|
+
puts "please enter 1-5:"
|
73
|
+
input = gets.strip
|
74
|
+
if input == "1"
|
75
|
+
puts "Here is a list of trails in Maryland:".black.on_green
|
76
|
+
state_menu(HikingGuide::Trail.md)
|
77
|
+
elsif input == "2"
|
78
|
+
puts "Here is a list of trails in Pennsylvania:".black.on_green
|
79
|
+
state_menu(HikingGuide::Trail.pa)
|
80
|
+
elsif input == "3"
|
81
|
+
puts "Here is a list of trails in North Carolina:".black.on_green
|
82
|
+
state_menu(HikingGuide::Trail.nc)
|
83
|
+
elsif input == "4"
|
84
|
+
puts "Here is a list of trails in Virgini:".black.on_green
|
85
|
+
state_menu(HikingGuide::Trail.va)
|
86
|
+
elsif input == "5"
|
87
|
+
puts "Here is a list of trails in West Virginia:".black.on_green
|
88
|
+
state_menu(HikingGuide::Trail.wv)
|
89
|
+
elsif input.upcase == "ALL TRAILS"
|
90
|
+
display_all_trails
|
91
|
+
elsif input.upcase == "EXIT"
|
92
|
+
exit
|
93
|
+
else
|
94
|
+
puts "I'm not sure what you mean -- let's see if we can find the trail again!".black.on_green
|
95
|
+
puts "<< at any time you can exit by typing 'exit' >>".black.on_green
|
96
|
+
main_menu
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.state_list(state_trails_list)
|
101
|
+
counter = 1
|
102
|
+
state_trails_list.each do |trail|
|
103
|
+
puts "(#{counter}) #{trail.name}"
|
104
|
+
counter += 1
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.state_menu(state_trails_list)
|
109
|
+
state_list(state_trails_list)
|
110
|
+
puts "Please type the number of any trail you'd like to learn more about"
|
111
|
+
puts "Or if you wish to return to the main menu, type 'menu'"
|
112
|
+
input = gets.strip
|
113
|
+
if input.to_i > 0 && input.to_i <= state_trails_list.size
|
114
|
+
display_trail_details(state_trails_list[input.to_i-1])
|
115
|
+
puts "Would you like to read about another of these trails? (y/n)"
|
116
|
+
response = gets.strip
|
117
|
+
if response.upcase == "Y"
|
118
|
+
state_menu(state_trails_list)
|
119
|
+
elsif response.upcase == "EXIT"
|
120
|
+
exit
|
121
|
+
else
|
122
|
+
main_menu
|
123
|
+
end
|
124
|
+
elsif input.upcase == "MENU"
|
125
|
+
main_menu
|
126
|
+
elsif input.upcase == "EXIT"
|
127
|
+
exit
|
128
|
+
else
|
129
|
+
puts "I'm not sure what you mean -- let's see if we can find the trail again!".black.on_green
|
130
|
+
puts "<< at any time you can exit by typing 'exit' >>".black.on_green
|
131
|
+
state_menu(state_trails_list)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.exit
|
136
|
+
puts "Thanks for visiting -- Happy Trails!"
|
137
|
+
hit_the_trails
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.display_trail_details(trail)
|
141
|
+
puts "----------------------".colorize(:light_green).on_green
|
142
|
+
puts " #{trail.name.upcase} ".colorize(:black).on_green
|
143
|
+
puts " state:".colorize(:black).on_green + " #{trail.state}"
|
144
|
+
puts " length:".colorize(:black).on_green + " #{trail.length}"
|
145
|
+
puts " hiking time:".colorize(:black).on_green + " #{trail.hiking_time}"
|
146
|
+
puts " elevation gain:".colorize(:black).on_green + " #{trail.elevation_gain}"
|
147
|
+
puts " link to map pdf:".colorize(:black).on_green + " #{trail.map_pdf_link}"
|
148
|
+
puts " trail description:".colorize(:black).on_green + " #{trail.description}"
|
149
|
+
puts " * * * * * * * ".colorize(:light_green)
|
150
|
+
puts "To read more about this trail, please visit #{trail.profile_url}"
|
151
|
+
puts "----------------------".colorize(:light_green).on_green
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.display_all_trails
|
155
|
+
HikingGuide::Trail.all.each do |trail|
|
156
|
+
display_trail_details(trail)
|
157
|
+
end
|
158
|
+
main_menu
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
#require 'open-uri'
|
2
|
+
|
3
|
+
class HikingGuide::Scraper
|
4
|
+
|
5
|
+
def self.scrape_trail_list(list_url)
|
6
|
+
page = Nokogiri::HTML(open(list_url))
|
7
|
+
state_trails = {
|
8
|
+
:md => page.css("#CollapsiblePanelOMH a"),
|
9
|
+
:nc => page.css("#CollapsiblePanelONCH a"),
|
10
|
+
:pa => page.css("#CollapsiblePanelOPH a"),
|
11
|
+
:va => page.css("#CollapsiblePanelOVH a"),
|
12
|
+
:wv => page.css("#CollapsiblePanelOWVH a"),
|
13
|
+
}
|
14
|
+
trail_array = []
|
15
|
+
state_trails.each do |state, trails|
|
16
|
+
trails.each do |trail|
|
17
|
+
trail_array << {
|
18
|
+
:name=> trail.children.text,
|
19
|
+
:profile_url=> HikingGuide::CommandLineInteface::BASE_PATH+trail.attributes["href"].value,
|
20
|
+
:state=> "#{state}".upcase
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
trail_array
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.scrape_trail_profile(profile_url)
|
28
|
+
page = Nokogiri::HTML(open(profile_url))
|
29
|
+
trail = {}
|
30
|
+
reference = page.css("td").find_index {|td| td.text == "Camping"}
|
31
|
+
|
32
|
+
page.css("td")[reference+1] != nil ?
|
33
|
+
trail[:length] = page.css("td")[reference+1].text.split.join(" ") : "unknown"
|
34
|
+
|
35
|
+
page.css("td")[reference+8].children[0] != nil ?
|
36
|
+
trail[:hiking_time] = page.css("td")[reference+8].children[0].text.split.join(" ") : "unknown"
|
37
|
+
|
38
|
+
page.css("td")[reference+8].children[2] != nil ?
|
39
|
+
trail[:elevation_gain] = page.css("td")[reference+8].children[2].text.split.join(" ") : "unknown"
|
40
|
+
|
41
|
+
page.css("p") != nil ?
|
42
|
+
trail[:description] = page.css("p").text.split.join(" ")[0..750].gsub(/\s\w+\s*$/, '...') : "unknown"
|
43
|
+
|
44
|
+
trail[:map_pdf_link] = profile_url+("images/Map.pdf")
|
45
|
+
|
46
|
+
trail
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
class HikingGuide::Trail
|
2
|
+
attr_accessor :name, :state, :profile_url, :length, :hiking_time, :elevation_gain, :map_pdf_link, :description
|
3
|
+
@@all = []
|
4
|
+
@@md = []
|
5
|
+
@@pa = []
|
6
|
+
@@nc = []
|
7
|
+
@@va = []
|
8
|
+
@@wv = []
|
9
|
+
|
10
|
+
def initialize(trail_hash)
|
11
|
+
trail_hash.each {|key, value| self.send("#{key}=", "#{value}")}
|
12
|
+
HikingGuide::Trail.all << self
|
13
|
+
HikingGuide::Trail.update_state_lists
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create_from_collection(trails_array)
|
17
|
+
trails_array.each do |trail|
|
18
|
+
if HikingGuide::Trail.all.include?(trail) == false
|
19
|
+
HikingGuide::Trail.new(trail)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_trail_attributes(attributes_hash)
|
25
|
+
attributes_hash.each {|key, value| self.send("#{key}=", "#{value}")}
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.update_state_lists
|
29
|
+
self.all.each do |trail|
|
30
|
+
case trail.state
|
31
|
+
when "MD"
|
32
|
+
self.md.include?(trail) ? nil : self.md << trail
|
33
|
+
when "PA"
|
34
|
+
self.pa.include?(trail) ? nil : self.pa << trail
|
35
|
+
when "NC"
|
36
|
+
self.nc.include?(trail) ? nil : self.nc << trail
|
37
|
+
when "VA"
|
38
|
+
self.va.include?(trail) ? nil : self.va << trail
|
39
|
+
when "WV"
|
40
|
+
self.wv.include?(trail) ? nil : self.wv << trail
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.all
|
46
|
+
@@all
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.md
|
50
|
+
@@md
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.pa
|
54
|
+
@@pa
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.nc
|
58
|
+
@@nc
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.va
|
62
|
+
@@va
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.wv
|
66
|
+
@@wv
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.reset_all
|
70
|
+
@@all.clear
|
71
|
+
@@md.clear
|
72
|
+
@@pa.clear
|
73
|
+
@@nc.clear
|
74
|
+
@@va.clear
|
75
|
+
@@wv.clear
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/spec.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Specifications for the CLI Assessment
|
2
|
+
|
3
|
+
Specs:
|
4
|
+
- [x] Have a CLI for interfacing with the application:
|
5
|
+
CLI includes a greeting, main menu, state trail lists, and individual trail profiles. Illustration and colors provide some fun.
|
6
|
+
|
7
|
+
- [x] Pull data from an external source:
|
8
|
+
Data pulled from http://www.hikingupward.com/
|
9
|
+
Trails pulled from lists by state on main page
|
10
|
+
Trail details pulled from individual trail profile pages
|
11
|
+
|
12
|
+
- [x] Implement both list and detail views:
|
13
|
+
States with available trails are listed, and trails within those states are listed. Individual trail details can be viewed.
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hiking_guide
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eleanor Graham
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.8.1
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0.8'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1.12'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: pry
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.10'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.10'
|
103
|
+
description: Hiking Guide is a CLI Gem that allows users to browse trails in the US
|
104
|
+
mid Atlantic region, taking descriptions from Hiking Upward.
|
105
|
+
email:
|
106
|
+
- eleanorcjkgraham@gmail.com
|
107
|
+
executables:
|
108
|
+
- hiking-guide
|
109
|
+
extensions: []
|
110
|
+
extra_rdoc_files: []
|
111
|
+
files:
|
112
|
+
- ".gitignore"
|
113
|
+
- ".rspec"
|
114
|
+
- ".travis.yml"
|
115
|
+
- CODE_OF_CONDUCT.md
|
116
|
+
- Gemfile
|
117
|
+
- Gemfile.lock
|
118
|
+
- LICENSE
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- bin/console
|
122
|
+
- bin/hiking-guide
|
123
|
+
- bin/setup
|
124
|
+
- hiking_guide.gemspec
|
125
|
+
- lib/hiking_guide.rb
|
126
|
+
- lib/hiking_guide/command_line_interface.rb
|
127
|
+
- lib/hiking_guide/scraper.rb
|
128
|
+
- lib/hiking_guide/trail.rb
|
129
|
+
- lib/hiking_guide/version.rb
|
130
|
+
- spec.md
|
131
|
+
homepage: https://github.com/eleanorgraham/hiking_guide
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata: {}
|
135
|
+
post_install_message: Thanks for installing! Hit the trails!
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib, lib/hiking_guide
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.4.5.1
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: CLI Gem that shows hiking trails from HikingUpward
|
155
|
+
test_files: []
|