hiking_project_cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +0 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +49 -0
- data/LICENSE.txt +21 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/hiking_project_cli +6 -0
- data/bin/setup +8 -0
- data/hiking_project_cli.gemspec +40 -0
- data/lib/hiking_project_cli/cli.rb +125 -0
- data/lib/hiking_project_cli/scraper.rb +62 -0
- data/lib/hiking_project_cli/trail.rb +69 -0
- data/lib/hiking_project_cli/version.rb +3 -0
- data/lib/hiking_project_cli.rb +15 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b6265d869688d7187f5b9897179e249f828cdac2eaea1f7fbbd064a0b8c258db
|
4
|
+
data.tar.gz: 52d109d1d47ba9dac402d6ab21b2cad9a270dac812bb018ca795aad72da83ba5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 944b0f89a5b45a3d378471a592d6f6715aae2fb865563fc2ba0f657f864994c42071d63bd28a6992976c2ebf6abce9af34d72998ca96aa108038e129dae66198
|
7
|
+
data.tar.gz: 5dd8ac298e4986be12e1be8f90d3687dff6a7b1f0080a5dc388feb58d4a02fcffbcc029e57fd1cb35febb6fc81acf4d57f2540693bd4131f3d0d7dcff8d68bd1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
File without changes
|
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 will.carter@fergusllc.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 [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hiking_project_cli (0.1.0)
|
5
|
+
dotenv
|
6
|
+
json
|
7
|
+
nokogiri
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
coderay (1.1.2)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
dotenv (2.7.5)
|
15
|
+
json (2.3.0)
|
16
|
+
method_source (0.9.2)
|
17
|
+
mini_portile2 (2.4.0)
|
18
|
+
nokogiri (1.10.7)
|
19
|
+
mini_portile2 (~> 2.4.0)
|
20
|
+
pry (0.12.2)
|
21
|
+
coderay (~> 1.1.0)
|
22
|
+
method_source (~> 0.9.0)
|
23
|
+
rake (12.3.3)
|
24
|
+
rspec (3.9.0)
|
25
|
+
rspec-core (~> 3.9.0)
|
26
|
+
rspec-expectations (~> 3.9.0)
|
27
|
+
rspec-mocks (~> 3.9.0)
|
28
|
+
rspec-core (3.9.1)
|
29
|
+
rspec-support (~> 3.9.1)
|
30
|
+
rspec-expectations (3.9.0)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-mocks (3.9.1)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-support (3.9.2)
|
37
|
+
|
38
|
+
PLATFORMS
|
39
|
+
ruby
|
40
|
+
|
41
|
+
DEPENDENCIES
|
42
|
+
bundler (~> 2.0)
|
43
|
+
hiking_project_cli!
|
44
|
+
pry
|
45
|
+
rake (~> 12.0)
|
46
|
+
rspec (~> 3.0)
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Will Carter
|
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,46 @@
|
|
1
|
+
# HikingProjectCli
|
2
|
+
|
3
|
+
This CLI application will provide a list of hiking trails and details for an latitide, longitide of interest. It is based on the Hiking Project DATA API https://www.hikingproject.com/data
|
4
|
+
|
5
|
+
It returns data publicly available pages on the Hiking Project site: https://www.hikingproject.com/
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
NOTE: you need to have a Hiking Project private key in order for this CLI to work.
|
10
|
+
|
11
|
+
1. Visit: https://www.hikingproject.com/ sign up for an account or contact me for a key: will.carter@fergusllc.com or find me on the Learn.co slack (Will Carter)
|
12
|
+
|
13
|
+
2. Visit https://www.hikingproject.com/data to see your key, copy it
|
14
|
+
|
15
|
+
---
|
16
|
+
|
17
|
+
$ git clone git@github.com:FergusDevelopmentLLC/hiking_project_cli.git
|
18
|
+
|
19
|
+
$ cd hiking_project_cli/
|
20
|
+
|
21
|
+
$ bundle install
|
22
|
+
|
23
|
+
$ touch .env
|
24
|
+
|
25
|
+
$ echo "HIKINGPROJECT_API_KEY=KEY_COPIED_FROM ABOVE" >> .env
|
26
|
+
|
27
|
+
$ sudo chmod +x bin/hiking_project_cli
|
28
|
+
|
29
|
+
$ ./bin/hiking_project_cli
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Follow the instructions in the program prompts.
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/FergusDevelopmentLLC/hiking_project_cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/FergusDevelopmentLLC/hiking_project_cli/blob/master/CODE_OF_CONDUCT.md).
|
38
|
+
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
43
|
+
|
44
|
+
## Code of Conduct
|
45
|
+
|
46
|
+
Everyone interacting in the HikingProjectCli project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/hiking_project_cli/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hiking_project_cli"
|
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
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative 'lib/hiking_project_cli/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "hiking_project_cli"
|
5
|
+
spec.version = HikingProjectCli::VERSION
|
6
|
+
spec.authors = ["Will Carter"]
|
7
|
+
spec.email = ["will.carter@fergusllc.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Shows hiking trails based on Hiking Project API}
|
10
|
+
spec.description = %q{Shows hiking trails based on Hiking Project API: https://www.hikingproject.com/data}
|
11
|
+
spec.homepage = "https://github.com/FergusDevelopmentLLC/hiking_project_cli"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/FergusDevelopmentLLC/hiking_project_cli"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/FergusDevelopmentLLC/hiking_project_cli/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.bindir = "bin"
|
31
|
+
spec.executables = ["hiking_project_cli"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "pry"
|
36
|
+
spec.add_dependency "json"
|
37
|
+
spec.add_dependency "dotenv"
|
38
|
+
spec.add_dependency "nokogiri"
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
class HikingProjectCli::CLI
|
2
|
+
|
3
|
+
def call
|
4
|
+
#welcome message to the user
|
5
|
+
puts "Welcome to the Hiking Project CLI"
|
6
|
+
puts "---------------------------------"
|
7
|
+
puts "Hiking Project API: https://www.hikingproject.com/data"
|
8
|
+
puts "Find hiking trails based on a latitude, longitude."
|
9
|
+
puts ""
|
10
|
+
puts "To find your coordinates:"
|
11
|
+
puts "1. On your computer, open Google Maps (https://www.google.com/maps)."
|
12
|
+
puts "2. Right-click the place or area on the map."
|
13
|
+
puts "3. Select What's here?"
|
14
|
+
puts "4. At the bottom, you’ll see a card with the coordinates."
|
15
|
+
puts "5. Copy and paste those coordinates below."
|
16
|
+
puts ""
|
17
|
+
puts "Here are some example coordinates:"
|
18
|
+
puts "Denver, CO: 39.74, -104.96"
|
19
|
+
puts "Chicago, IL: 41.83, -87.64"
|
20
|
+
puts "New York, NY: 40.73, -73.99"
|
21
|
+
puts "San Francisco, CA: 37.75, -122.44"
|
22
|
+
puts ""
|
23
|
+
get_coordinates
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_coordinates
|
27
|
+
#get coordinates from user
|
28
|
+
puts "Please enter your latitude, longitude:"
|
29
|
+
|
30
|
+
coord_input = ""
|
31
|
+
while coord_input == "" || HikingProjectCli::CLI.is_coord_valid(coord_input) == false
|
32
|
+
coord_input = gets.strip
|
33
|
+
if(coord_input == "exit")
|
34
|
+
goodbye
|
35
|
+
end
|
36
|
+
puts "Invalid coordinates. Please enter a valid latitude, longitude within the United States." unless HikingProjectCli::CLI.is_coord_valid(coord_input)
|
37
|
+
end
|
38
|
+
|
39
|
+
@coords = coord_input
|
40
|
+
|
41
|
+
HikingProjectCli::Trail.clear()
|
42
|
+
list_trails
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.is_coord_valid(coord_input)
|
46
|
+
if coord_input.match(/\A([-]?[1-9]+|[-]?[1-9]+\d*|[-]?[1-9]+\d*\.\d+),[\s]?([-]?[1-9]+|[-]?[1-9]+\d*|[-]?[1-9]+\d*\.\d+)\z/)
|
47
|
+
#split coord_input into array
|
48
|
+
coord_input = coord_input.gsub(" ", "")
|
49
|
+
coord_input_array = coord_input.split(",")
|
50
|
+
if(coord_input_array[0].to_f.between?(18.91619, 71.3577635769) && coord_input_array[1].to_f.between?(-171.791110603, -66.96466))
|
51
|
+
true
|
52
|
+
else
|
53
|
+
false
|
54
|
+
end
|
55
|
+
else
|
56
|
+
false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def list_trails
|
61
|
+
@coords = @coords.gsub(" ", "")
|
62
|
+
coords_array = @coords.split(",")
|
63
|
+
coords_qs = "lat=#{coords_array[0]}&lon=#{coords_array[1]}"
|
64
|
+
|
65
|
+
if HikingProjectCli::Trail.all.length == 0
|
66
|
+
trail_hashes_from_api = HikingProjectCli::Scraper.get_trails_from_api(coords_qs)
|
67
|
+
trails = HikingProjectCli::Trail.create_from_collection(trail_hashes_from_api)
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "Trails for latitude: #{coords_array[0]} longitude: #{coords_array[1]}"
|
71
|
+
puts "-----------------------------------------------"
|
72
|
+
if(HikingProjectCli::Trail.all.length > 0)
|
73
|
+
HikingProjectCli::Trail.all.each.with_index(1) {|trail, index|
|
74
|
+
puts "#{index} - #{trail.print_summary}"
|
75
|
+
}
|
76
|
+
else
|
77
|
+
puts "No trails found for those coordinates."
|
78
|
+
end
|
79
|
+
puts "-----------------------------------------------"
|
80
|
+
|
81
|
+
menu
|
82
|
+
end
|
83
|
+
|
84
|
+
def menu
|
85
|
+
# valid inputs: any from the list or list, restart, exit
|
86
|
+
|
87
|
+
valid_inputs = HikingProjectCli::Trail.all.each.with_index(1).map {|trail, index| index.to_s}
|
88
|
+
valid_inputs = valid_inputs.concat ["restart", "list", "exit"]
|
89
|
+
|
90
|
+
puts "Enter the number of the trail you would like more information on, list to relist, restart, or exit."
|
91
|
+
|
92
|
+
input = ""
|
93
|
+
while input == "" || valid_inputs.include?(input) == false
|
94
|
+
input = gets.strip
|
95
|
+
puts "Invalid entry, please enter the number of the trail, list to relist, restart or exit." unless valid_inputs.include?(input)
|
96
|
+
end
|
97
|
+
|
98
|
+
#allows user to relist trails, choose a trail to show detail, restart, or exit
|
99
|
+
if input == "restart"
|
100
|
+
call
|
101
|
+
elsif input == "list"
|
102
|
+
list_trails
|
103
|
+
elsif input == "exit"
|
104
|
+
goodbye
|
105
|
+
else
|
106
|
+
#get selected trail.url
|
107
|
+
selected_trail = HikingProjectCli::Trail.all[input.to_i - 1]
|
108
|
+
show_full_description(selected_trail)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def show_full_description(trail)
|
113
|
+
#display trail full details
|
114
|
+
trail_details_hash = HikingProjectCli::Scraper.scrape_trail_detail(trail.url)
|
115
|
+
trail.add_full_details(trail_details_hash)
|
116
|
+
trail.print_full_description
|
117
|
+
menu
|
118
|
+
end
|
119
|
+
|
120
|
+
def goodbye
|
121
|
+
puts "-----------------------------------------------"
|
122
|
+
puts "Thank you for using the Hiking Project CLI"
|
123
|
+
exit!
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
class HikingProjectCli::Scraper
|
2
|
+
|
3
|
+
def self.get_trails_from_api(coords)
|
4
|
+
|
5
|
+
#returns an array of trail hashes
|
6
|
+
|
7
|
+
#coords = "lat=40.0274&lon=-105.2519"
|
8
|
+
#coords = "lat=28.539358&lon=-81.398444"
|
9
|
+
|
10
|
+
url = "https://www.hikingproject.com/data/get-trails?#{coords}&maxDistance=10&key=#{ENV['HIKINGPROJECT_API_KEY']}"
|
11
|
+
uri = URI(url)
|
12
|
+
response = Net::HTTP.get(uri)
|
13
|
+
api_trails = JSON.parse(response)
|
14
|
+
|
15
|
+
api_trails["trails"].map {|trail|
|
16
|
+
{
|
17
|
+
:name => trail["name"],
|
18
|
+
:length => trail["length"],
|
19
|
+
:summary => trail["summary"],
|
20
|
+
:url => trail["url"],
|
21
|
+
:location => trail["location"],
|
22
|
+
:difficulty => trail["difficulty"],
|
23
|
+
:stars => trail["stars"],
|
24
|
+
:ascent => trail["ascent"],
|
25
|
+
:descent => trail["descent"],
|
26
|
+
:high => trail["high"],
|
27
|
+
:low => trail["low"],
|
28
|
+
:conditionStatus => trail["conditionStatus"],
|
29
|
+
:conditionDetails => trail["conditionDetails"],
|
30
|
+
:conditionDate => trail["conditionDate"]
|
31
|
+
}
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.scrape_trail_detail(trail_url)
|
36
|
+
#returns a trail detail hash (features, overview, description)
|
37
|
+
|
38
|
+
trail_details_hash = {}
|
39
|
+
|
40
|
+
doc = Nokogiri::HTML(open(trail_url))
|
41
|
+
|
42
|
+
#https://stackoverflow.com/questions/1474688/nokogiri-how-to-select-nodes-by-matching-text
|
43
|
+
#https://stackoverflow.com/questions/5393593/how-do-i-get-the-next-html-element-in-nokogiri
|
44
|
+
features_h3 = doc.at('h3:contains("Features")')
|
45
|
+
if features_h3
|
46
|
+
trail_details_hash[:features] = features_h3.search("span").text.strip
|
47
|
+
end
|
48
|
+
|
49
|
+
overview_h3 = doc.at('h3:contains("Overview")')
|
50
|
+
if overview_h3
|
51
|
+
trail_details_hash[:overview] = overview_h3.next_element.text.strip.gsub(/[\r\n]+/, "")
|
52
|
+
end
|
53
|
+
|
54
|
+
desc_h3 = doc.at('h3:contains("Description")')
|
55
|
+
if desc_h3
|
56
|
+
trail_details_hash[:description] = desc_h3.next_element.text.strip.gsub(/[\r\n]+/, "")
|
57
|
+
end
|
58
|
+
|
59
|
+
trail_details_hash
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class HikingProjectCli::Trail
|
2
|
+
|
3
|
+
attr_accessor :name, :length, :summary, :location, :difficulty, :stars, :ascent, :descent, :high, :low, :conditionStatus, :conditionDetails, :conditionDate, :url, :features, :overview, :description
|
4
|
+
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def initialize(trail_hash)
|
8
|
+
trail_hash.each {|key, value| self.send(("#{key}="), value)}
|
9
|
+
@@all << self
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create_from_collection(trails_array)
|
13
|
+
trails_array.each {|trail|
|
14
|
+
HikingProjectCli::Trail.new(trail)
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_full_details(details_hash)
|
19
|
+
details_hash.each {|key, value| self.send(("#{key}="), value)}
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.all
|
24
|
+
@@all
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.clear
|
28
|
+
@@all = Array.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def print_summary
|
32
|
+
if (self.summary != nil && self.summary != "Needs Summary" && self.summary != "")
|
33
|
+
"#{self.name} (#{self.length.to_s} miles) - #{self.summary}"
|
34
|
+
else
|
35
|
+
"#{self.name} (#{self.length.to_s} miles)"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def print_full_description
|
40
|
+
puts "-----------------------------------------------"
|
41
|
+
puts "#{self.name} (#{self.length} miles)"
|
42
|
+
puts ""
|
43
|
+
puts "Location: #{self.location}" unless self.location == nil
|
44
|
+
puts "Summary: #{self.summary}" unless (self.summary == nil || self.summary == "Needs Summary" || self.summary == "")
|
45
|
+
puts "Difficulty: #{self.difficulty}" unless self.difficulty == nil
|
46
|
+
puts "Stars: #{self.stars}" unless self.stars == nil
|
47
|
+
puts "Ascent: #{self.ascent}" unless self.ascent == nil
|
48
|
+
puts "Descent: #{self.descent}" unless self.descent == nil
|
49
|
+
puts "High: #{self.high}" unless self.high == nil
|
50
|
+
puts "Low: #{self.low}" unless self.low == nil
|
51
|
+
puts "Condition Status: #{self.conditionStatus}" unless (self.conditionStatus == nil || self.conditionStatus == "Unknown")
|
52
|
+
puts "Condition Details: #{self.conditionDetails}" unless self.conditionDetails == nil
|
53
|
+
puts "Condition Date: #{self.conditionDate}" unless (self.conditionDate == nil || self.conditionDate == "1970-01-01 00:00:00")
|
54
|
+
|
55
|
+
puts "" unless (self.features == nil || self.features == "-none-")
|
56
|
+
puts "Features:" unless (self.features == nil || self.features == "-none-")
|
57
|
+
puts "#{self.features}" unless (self.features == nil || self.features == "-none-")
|
58
|
+
|
59
|
+
puts "" unless self.overview == nil
|
60
|
+
puts "Overview:" unless self.overview == nil
|
61
|
+
puts "#{self.overview}" unless self.overview == nil
|
62
|
+
|
63
|
+
puts "" unless self.description == nil
|
64
|
+
puts "Description:" unless self.description == nil
|
65
|
+
puts "#{self.description}" unless self.description == nil
|
66
|
+
puts ""
|
67
|
+
puts "-----------------------------------------------"
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'dotenv/load'
|
6
|
+
|
7
|
+
require_relative "hiking_project_cli/version"
|
8
|
+
require_relative "hiking_project_cli/cli"
|
9
|
+
require_relative "hiking_project_cli/scraper"
|
10
|
+
require_relative "hiking_project_cli/trail"
|
11
|
+
|
12
|
+
module HikingProjectCli
|
13
|
+
class Error < StandardError; end
|
14
|
+
# Your code goes here...
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hiking_project_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Will Carter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-03 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: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
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: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nokogiri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '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'
|
97
|
+
description: 'Shows hiking trails based on Hiking Project API: https://www.hikingproject.com/data'
|
98
|
+
email:
|
99
|
+
- will.carter@fergusllc.com
|
100
|
+
executables:
|
101
|
+
- hiking_project_cli
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CHANGELOG.md
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- bin/console
|
116
|
+
- bin/hiking_project_cli
|
117
|
+
- bin/setup
|
118
|
+
- hiking_project_cli.gemspec
|
119
|
+
- lib/hiking_project_cli.rb
|
120
|
+
- lib/hiking_project_cli/cli.rb
|
121
|
+
- lib/hiking_project_cli/scraper.rb
|
122
|
+
- lib/hiking_project_cli/trail.rb
|
123
|
+
- lib/hiking_project_cli/version.rb
|
124
|
+
homepage: https://github.com/FergusDevelopmentLLC/hiking_project_cli
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata:
|
128
|
+
allowed_push_host: https://rubygems.org
|
129
|
+
homepage_uri: https://github.com/FergusDevelopmentLLC/hiking_project_cli
|
130
|
+
source_code_uri: https://github.com/FergusDevelopmentLLC/hiking_project_cli
|
131
|
+
changelog_uri: https://github.com/FergusDevelopmentLLC/hiking_project_cli/CHANGELOG.md
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 2.3.0
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubygems_version: 3.0.3
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Shows hiking trails based on Hiking Project API
|
151
|
+
test_files: []
|