colorado_trails 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +48 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +1 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/run +14 -0
- data/bin/self.attribute +28 -0
- data/bin/setup +9 -0
- data/colorado_trails.gemspec +50 -0
- data/lib/colorado_trails/cli.rb +139 -0
- data/lib/colorado_trails/scraper.rb +91 -0
- data/lib/colorado_trails/trails.rb +52 -0
- data/lib/colorado_trails/version.rb +3 -0
- data/lib/colorado_trails.rb +15 -0
- metadata +22 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b465227589415f06c9f58c295dd27e8933ebc3ac4bd636d75fd693ff7b8d053f
|
4
|
+
data.tar.gz: 17a0f6fa6cfeb9abac785d20696aa3c2302b05e5ecb1d0cfbc7eaf67de9d52fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3afecf468044cee564bf495e4688a2a91bdc4e86684c99a65376084367d6873bc4ab89d1270cdab27c21a933784c69a13291d4fc3f9002fce8d65c52f5b2c82c
|
7
|
+
data.tar.gz: 8683b34bb7d64d6938e63d4cccfa97b62beae69644ebd363d3fac24f36cd15a490fb323bddbdb1034a8c20c65660c64e0666ac8d15201495f7294f59cbabd3b9
|
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 46858206+ChrstphGrnr@users.noreply.github.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/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
colorado_trails (0.1.0)
|
5
|
+
artii
|
6
|
+
colorize
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
artii (2.1.2)
|
12
|
+
coderay (1.1.2)
|
13
|
+
colorize (0.8.1)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
method_source (0.9.2)
|
16
|
+
mini_portile2 (2.4.0)
|
17
|
+
nokogiri (1.10.1)
|
18
|
+
mini_portile2 (~> 2.4.0)
|
19
|
+
pry (0.12.2)
|
20
|
+
coderay (~> 1.1.0)
|
21
|
+
method_source (~> 0.9.0)
|
22
|
+
rake (10.5.0)
|
23
|
+
rspec (3.8.0)
|
24
|
+
rspec-core (~> 3.8.0)
|
25
|
+
rspec-expectations (~> 3.8.0)
|
26
|
+
rspec-mocks (~> 3.8.0)
|
27
|
+
rspec-core (3.8.0)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-expectations (3.8.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-mocks (3.8.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-support (3.8.0)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bundler (~> 2.0)
|
42
|
+
nokogiri
|
43
|
+
pry
|
44
|
+
rake (~> 10.0)
|
45
|
+
rspec (~> 3.0)
|
46
|
+
|
47
|
+
BUNDLED WITH
|
48
|
+
2.0.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 Christoph Gruener
|
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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 ChrstphGrnr
|
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 @@
|
|
1
|
+
# off_road_trails
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "colorado_trails"
|
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/run
ADDED
data/bin/self.attribute
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
[1mFrom:[0m /mnt/c/Users/Christoph/off_road_trails/lib/colorado_trails/trails.rb @ line 40 ColoradoTrails::Trails#showcase_details:
|
3
|
+
|
4
|
+
[1;34m31[0m: [32mdef[0m [1;34mshowcase_details[0m
|
5
|
+
[1;34m32[0m: [1;34m# binding.pry[0m
|
6
|
+
[1;34m33[0m: attributes = [name, location, rating, description, type, url, difficulty, distance, duration]
|
7
|
+
[1;34m34[0m: trail_name = [1;36mself[0m.name.delete([31m[1;31m"[0m[31m(/[1;35m\#[0m[31m|[0-9]/)[1;31m"[0m[31m[0m).strip
|
8
|
+
[1;34m35[0m:
|
9
|
+
[1;34m36[0m: puts [31m[1;31m"[0m[31m[1;35m\n[0m[31m[1;35m\n[0m[31mHere are the details for #{trail_name}[0m[31m[1;35m\n[0m[31m[1;35m\n[0m[31m:[1;31m"[0m[31m[0m
|
10
|
+
[1;34m37[0m:
|
11
|
+
[1;34m38[0m: attributes.each [32mdo[0m |attribute|
|
12
|
+
[1;34m39[0m: [32mif[0m attribute != [1;36mnil[0m
|
13
|
+
=> [1;34m40[0m: binding.pry
|
14
|
+
[1;34m41[0m: puts [31m[1;31m"[0m[31m#{attribute}[0m[31m: #{self.attribute}[0m[31m[1;31m"[0m[31m[0m
|
15
|
+
[1;34m42[0m: [32mend[0m
|
16
|
+
[1;34m43[0m: [32mend[0m
|
17
|
+
[1;34m44[0m:
|
18
|
+
[1;34m45[0m: [1;34m# puts "Rating: #{self.rating}"[0m
|
19
|
+
[1;34m46[0m: [1;34m# puts "Trail Type: #{self.type}"[0m
|
20
|
+
[1;34m47[0m: [1;34m# puts "Distance #{self.distance}"[0m
|
21
|
+
[1;34m48[0m: [1;34m# puts "Duration #{self.duration}"[0m
|
22
|
+
[1;34m49[0m: [1;34m# puts "Difficulty #{self.difficulty}"[0m
|
23
|
+
[1;34m50[0m: [1;34m# puts "Website #{self.url}"[0m
|
24
|
+
[1;34m51[0m: [32mif[0m [1;36mself[0m.description != [1;36mnil[0m
|
25
|
+
[1;34m52[0m: puts [31m[1;31m"[0m[31m[1;35m\n[0m[31m[1;35m\n[0m[31mHere is a short description of the trail:[1;35m\n[0m[31m#{self.description.scan([1;31m/[0m[31m.{1,66} [1;31m/[0m[31m[0m[31m).join([1;31m"[0m[31m[1;35m\n[0m[31m[1;31m"[0m[31m[0m[31m)}[0m[31m[1;31m"[0m[31m[0m
|
26
|
+
[1;34m53[0m: [32mend[0m
|
27
|
+
[1;34m54[0m: [32mend[0m
|
28
|
+
|
data/bin/setup
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "colorado_trails/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "colorado_trails"
|
8
|
+
spec.version = ColoradoTrails::VERSION
|
9
|
+
spec.authors = ["ChrstphGrnr"]
|
10
|
+
spec.email = ["46858206+ChrstphGrnr@users.noreply.github.com"]
|
11
|
+
|
12
|
+
spec.summary = "Colorado Trails Gem"
|
13
|
+
spec.description = "Developed for access to Colorado's Top 20 trails in a variety of categories."
|
14
|
+
spec.homepage = "https://github.com/ChrstphGrnr/colorado_trails.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
|
22
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
# spec.metadata["source_code_uri"] = "https://github.com/ChrstphGrnr/colorado_trails"
|
24
|
+
|
25
|
+
# else
|
26
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
# "public gem pushes."
|
28
|
+
# end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_development_dependency 'pry'
|
43
|
+
spec.add_development_dependency 'nokogiri'
|
44
|
+
|
45
|
+
spec.add_dependency 'colorize'
|
46
|
+
spec.add_dependency 'artii'
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
class ColoradoTrails::CLI
|
4
|
+
|
5
|
+
attr_accessor :input, :user_name, :trails
|
6
|
+
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
name
|
10
|
+
welcome
|
11
|
+
menu
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def name
|
16
|
+
a = Artii::Base.new
|
17
|
+
puts a.asciify('Colorado Trails!').colorize(:light_blue)
|
18
|
+
puts "\nWelcome to Colorado Trails!\n \nThis app can provide you with detailed info on the Top 20 trails in a variety of categories.".colorize(:light_blue)
|
19
|
+
puts "Before we begin, would you mind telling me your name?\n".colorize(:light_blue)
|
20
|
+
@user_name = gets.chomp
|
21
|
+
end
|
22
|
+
|
23
|
+
def welcome
|
24
|
+
puts "\nHello #{@user_name}, welcome! Are you ready to explore the trails?".colorize(:light_blue)
|
25
|
+
end
|
26
|
+
|
27
|
+
def menu
|
28
|
+
sleep(0.5)
|
29
|
+
puts "\nPlease chose from the following trail options:\n".colorize(:light_blue)
|
30
|
+
puts "-> Press [1] for the ".colorize(:light_blue)+"Top 20 hiking trails".colorize(:light_green)+" in Colorado.".colorize(:light_blue)
|
31
|
+
puts "-> Press [2] for the ".colorize(:light_blue)+"Top 20 offroad trails".colorize(:light_green)+" in Colorado.".colorize(:light_blue)
|
32
|
+
puts "-> Press [3] for the ".colorize(:light_blue)+"Top 20 mountain-biking trails".colorize(:light_green)+" in Colorado.".colorize(:light_blue)
|
33
|
+
puts "\n-> Type 'exit' to end this program.\n".colorize(:light_red)
|
34
|
+
|
35
|
+
input = gets.chomp.downcase
|
36
|
+
|
37
|
+
if input.length == 1
|
38
|
+
input = input.to_i\
|
39
|
+
elsif input == "quit"
|
40
|
+
input = "exit"
|
41
|
+
end
|
42
|
+
|
43
|
+
case input
|
44
|
+
|
45
|
+
when 1
|
46
|
+
puts "\n\n...loading hiking trails. This may take a moment.\n\n\n"
|
47
|
+
trail_list(:hiking)
|
48
|
+
ColoradoTrails::Trails.name_location
|
49
|
+
|
50
|
+
menu_2
|
51
|
+
|
52
|
+
when 2
|
53
|
+
puts "\n...loading offroad trails. This may take a moment.\n\n\n"
|
54
|
+
trail_list(:offroad)
|
55
|
+
ColoradoTrails::Trails.name_location
|
56
|
+
|
57
|
+
menu_2
|
58
|
+
|
59
|
+
when 3
|
60
|
+
puts "\n...loading mountain-biking trails. This may take a moment. \n\n\n"
|
61
|
+
trail_list(:mountainbiking)
|
62
|
+
ColoradoTrails::Trails.name_location
|
63
|
+
|
64
|
+
menu_2
|
65
|
+
|
66
|
+
when "menu"
|
67
|
+
menu
|
68
|
+
when "exit"
|
69
|
+
over_and_out
|
70
|
+
else
|
71
|
+
puts "Not a valid input!".colorize(:light_red)
|
72
|
+
menu
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def trail_list(input)
|
78
|
+
ColoradoTrails::Scraper.trail_list(input)
|
79
|
+
end
|
80
|
+
|
81
|
+
def menu_2
|
82
|
+
|
83
|
+
puts "\nPlease chose from the following options:".colorize(:light_blue)
|
84
|
+
puts "\n-> Select a specific trail by it's number.".colorize(:light_blue)
|
85
|
+
puts "-> Type 'menu' to return to the previous menu.".colorize(:light_blue)
|
86
|
+
puts "\n-> Type 'exit' to end this program.\n".colorize(:light_red)
|
87
|
+
|
88
|
+
input = gets.chomp.downcase
|
89
|
+
|
90
|
+
input.include?("#") ? input.delete!("#") : input
|
91
|
+
if input.to_i.between?(1, ColoradoTrails::Trails.all.length)
|
92
|
+
trail = ColoradoTrails::Trails.all[input.to_i - 1]
|
93
|
+
ColoradoTrails::Scraper.trail_details(trail)
|
94
|
+
trail.showcase_details
|
95
|
+
self.menu_3(trail)
|
96
|
+
|
97
|
+
elsif input == "menu"
|
98
|
+
self.menu
|
99
|
+
elsif input == "exit" || input == "quit"
|
100
|
+
self.over_and_out
|
101
|
+
else
|
102
|
+
puts "\nI don't understand your choice, please try again.".colorize(:light_red)
|
103
|
+
self.menu_2
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
def menu_3(trail)
|
109
|
+
puts "\nThe following options are available:\n".colorize(:light_blue)
|
110
|
+
puts "-> Type 'menu' to return to the main menu for a choice of different types of trails.".colorize(:light_blue)
|
111
|
+
puts "-> Type 'trail' to return to the trails menu for more trails like#{trail.name.delete("(/\#|[0-9]/)")}.".colorize(:light_blue)
|
112
|
+
puts "\n-> Type 'exit' to end this program.\n\n".colorize(:light_red)
|
113
|
+
|
114
|
+
new_input = gets.chomp.downcase
|
115
|
+
case new_input
|
116
|
+
when 'menu'
|
117
|
+
ColoradoTrails::Trails.clear
|
118
|
+
self.menu
|
119
|
+
when 'trail'
|
120
|
+
ColoradoTrails::Trails.name_location
|
121
|
+
self.menu_2
|
122
|
+
when 'exit'
|
123
|
+
self.over_and_out
|
124
|
+
when 'quit'
|
125
|
+
self.over_and_out
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def over_and_out
|
130
|
+
puts "\nGoodbye ".colorize(:light_red)+"#{@user_name}".colorize(:white)+", thanks for exploring with us!\n".colorize(:light_red)
|
131
|
+
puts "Come back soon to your...".colorize(:light_red)
|
132
|
+
a = Artii::Base.new
|
133
|
+
puts a.asciify('Colorado Trails!').colorize(:light_blue)
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
|
139
|
+
|
@@ -0,0 +1,91 @@
|
|
1
|
+
|
2
|
+
class ColoradoTrails::Scraper
|
3
|
+
|
4
|
+
|
5
|
+
def self.trail_list(input)
|
6
|
+
|
7
|
+
ColoradoTrails::Trails.clear
|
8
|
+
|
9
|
+
self.site(input)
|
10
|
+
|
11
|
+
### refactor to do it all in one .each ?
|
12
|
+
|
13
|
+
trails = Nokogiri::HTML(open(@site)).css('div.trails-listing')
|
14
|
+
|
15
|
+
trails.css('div.trail-info div.name').each {|trail| ColoradoTrails::Trails.new(trail.text)}
|
16
|
+
|
17
|
+
trails.css('div.state').each_with_index {|location, i| ColoradoTrails::Trails.all[i].location = location.text.chomp(', CO')}
|
18
|
+
|
19
|
+
trails.css('div.img-wrapper a').each_with_index {|url, i| ColoradoTrails::Trails.all[i].url = "https://www.trails.com" + url.attribute('href').value}
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.site(input)
|
24
|
+
if input == :offroad
|
25
|
+
@site = "https://www.trails.com/toptrails.aspx?state=co&activity=od"
|
26
|
+
elsif input == :hiking
|
27
|
+
@site = "https://www.trails.com/toptrails.aspx?state=co&activity=hk"
|
28
|
+
elsif input == :mountainbiking
|
29
|
+
@site = "https://www.trails.com/toptrails.aspx?state=co&activity=mb"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.trail_details(trail)
|
35
|
+
|
36
|
+
site = trail.url
|
37
|
+
|
38
|
+
doc = Nokogiri::HTML(open(site)).css('div.Wrapper')
|
39
|
+
|
40
|
+
info = doc.css('div.info_Data').collect {|label| label.text.strip}
|
41
|
+
labels = doc.css('div.info_label').collect {|info| info.text.strip}
|
42
|
+
|
43
|
+
if doc.css('div#elevation-wrapper').empty?
|
44
|
+
|
45
|
+
#refactor to send_method instead of case_method
|
46
|
+
|
47
|
+
labels.each_with_index do |label, i|
|
48
|
+
case label.downcase.strip
|
49
|
+
when "trail type"
|
50
|
+
trail.type = info[i].strip
|
51
|
+
when "difficulty"
|
52
|
+
trail.difficulty = info[i].strip
|
53
|
+
when "skill level"
|
54
|
+
trail.difficulty = info[i].strip
|
55
|
+
when "duration"
|
56
|
+
trail.duration = info[i].strip
|
57
|
+
when "distance"
|
58
|
+
trail.distance = info[i].strip + " miles"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
else
|
63
|
+
labels.each_with_index do |label, i|
|
64
|
+
case label.downcase.strip
|
65
|
+
when "trail type"
|
66
|
+
trail.type = info[i].strip
|
67
|
+
when "difficulty"
|
68
|
+
trail.difficulty = info[i].strip
|
69
|
+
when "skill level"
|
70
|
+
trail.difficulty = info[i].strip
|
71
|
+
when "duration"
|
72
|
+
trail.duration = info[i].strip
|
73
|
+
end
|
74
|
+
end
|
75
|
+
trail.distance = doc.css('span.value').first.text + " miles"
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
trail.rating = "#{doc.css('div.rating-section').children.css('img').attribute('alt').text[0]}/5 stars"
|
80
|
+
|
81
|
+
trail.description = nil
|
82
|
+
# binding.pry
|
83
|
+
if !doc.css('p.summary').empty?
|
84
|
+
trail.description = doc.css('p.summary').text.delete'(/["]/)'
|
85
|
+
else
|
86
|
+
trail.description = doc.css('div#TrailDetailsDescription').text
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class ColoradoTrails::Trails
|
2
|
+
|
3
|
+
attr_accessor :name, :location, :rating, :description, :type, :url,
|
4
|
+
:difficulty, :distance, :duration
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
def initialize(name= nil, location= nil, rating= nil, url= nil)
|
8
|
+
@name = name
|
9
|
+
@@all << self
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def self.all
|
14
|
+
@@all
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.clear
|
18
|
+
@@all.clear
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.name_location
|
22
|
+
puts "Trail".colorize(:light_green).ljust(84) + "Location\n".colorize(:light_green)
|
23
|
+
@@all.each do |trail|
|
24
|
+
puts trail.name.ljust(70).colorize(:light_blue) + trail.location.colorize(:light_blue)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
def showcase_details
|
32
|
+
|
33
|
+
trail_name = self.name.delete("(/\#|[0-9]/)").strip
|
34
|
+
|
35
|
+
puts "\n\nHere are the details for #{trail_name}:\n\n".colorize(:light_blue)
|
36
|
+
puts "Rating: #{self.rating}".colorize(:light_blue) unless self.rating == nil || self.rating.empty?
|
37
|
+
puts "Trail Type: #{self.type}".colorize(:light_blue) unless self.type == nil || self.type.empty?
|
38
|
+
puts "Distance #{self.distance}".colorize(:light_blue) unless self.distance == nil || self.distance.empty?
|
39
|
+
puts "Duration #{self.duration}".colorize(:light_blue) unless self.duration == nil || self.duration.empty?
|
40
|
+
puts "Difficulty #{self.difficulty}".colorize(:light_blue) unless self.difficulty == nil || self.duration.empty?
|
41
|
+
puts "Website #{self.url}".colorize(:light_blue)
|
42
|
+
|
43
|
+
if self.description != nil || self.description != ""
|
44
|
+
# binding.pry
|
45
|
+
self.description = self.description + " "
|
46
|
+
puts "\n\nHere is a short description of the trail:\n\n#{self.description.scan(/.{1,66} /).join("\n")}".colorize(:light_blue)
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'pry'
|
5
|
+
require 'openssl'
|
6
|
+
require 'colorize'
|
7
|
+
require 'artii'
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
require_relative "./colorado_trails/version.rb"
|
12
|
+
require_relative "./colorado_trails/cli.rb"
|
13
|
+
require_relative "./colorado_trails/trails.rb"
|
14
|
+
require_relative "./colorado_trails/scraper.rb"
|
15
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorado_trails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ChrstphGrnr
|
@@ -114,7 +114,27 @@ email:
|
|
114
114
|
executables: []
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
|
-
files:
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CODE_OF_CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/run
|
130
|
+
- bin/self.attribute
|
131
|
+
- bin/setup
|
132
|
+
- colorado_trails.gemspec
|
133
|
+
- lib/colorado_trails.rb
|
134
|
+
- lib/colorado_trails/cli.rb
|
135
|
+
- lib/colorado_trails/scraper.rb
|
136
|
+
- lib/colorado_trails/trails.rb
|
137
|
+
- lib/colorado_trails/version.rb
|
118
138
|
homepage: https://github.com/ChrstphGrnr/colorado_trails.git
|
119
139
|
licenses:
|
120
140
|
- MIT
|