washington_hikes 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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/.vscode/settings.json +4 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/Notes +16 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/bin/washington-hikes +5 -0
- data/lib/washington_hikes.rb +9 -0
- data/lib/washington_hikes/cli.rb +150 -0
- data/lib/washington_hikes/hike.rb +33 -0
- data/lib/washington_hikes/region.rb +51 -0
- data/lib/washington_hikes/scraper.rb +51 -0
- data/lib/washington_hikes/version.rb +3 -0
- data/washington_hikes.gemspec +40 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 655c10441dda8af5c3a4352dbdec77af4c6a44852869df8e4a6ef01d58a2e8e4
|
4
|
+
data.tar.gz: d11a9f710f26a5e9356247815e585f65e1048df17b87b1526b15bb28c2c4f5c3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b2c7ede7ed4196eb85e711408e59fcb67d977b51ddccc8a01cd415078d5e4873db9844bb601ec046855c89ecab2353c01f42731fb59c96645d7f67d0ed99af9e
|
7
|
+
data.tar.gz: a61bd1f2c700b6341b8d9db6efb88e650bb5c7ff2d508083cfda6dad3952187efd70612e6a5f84d94a2a49369534b9546d83a44ed45d918b05ead88a94aa73ad
|
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 TODO: Write your email address. 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) 2018 TODO: Write your name
|
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/Notes
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Description:
|
2
|
+
|
3
|
+
WashingtonHikesCLI will be a command-line app to allow a user to find a hike in a specified region of Washington state, and potentially filter available hikes based on additional properties such as hike length and elevation gain. When the user runs the app, they will see a greeting and be able to type a number corresponding to one of the following actions: choose the region they would like to look in, see all hikes, or exit the app. Hikes will be scraped from wta.org based on filter criteria.
|
4
|
+
|
5
|
+
If a user chooses to select a region, they will be asked to choose a region from a list scraped from wta.org or type 'back' to get to the main menu. If they select a region they will see a list of hikes available in that region including the name, length and elevation gain. The user can select a hike (by typing the corresponding number) to see additional details like the description.
|
6
|
+
|
7
|
+
From the main menu, if a user types "all" they will see a list of hikes across all regions and if they type "exit" they will exit the app.
|
8
|
+
|
9
|
+
The user will not be able to create or edit hikes.
|
10
|
+
|
11
|
+
This CLI project will have three classes: Hike, HikeScraper and WashingtonHikesCLI.
|
12
|
+
|
13
|
+
|
14
|
+
QUESTIONS
|
15
|
+
1. how do I make my code run without "ruby" before the executables on a Windows device?
|
16
|
+
2.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# WashingtonHikes
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/washington_hikes`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'washington_hikes'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install washington_hikes
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/washington_hikes. 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.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the WashingtonHikes project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/washington_hikes/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require_relative '../lib/washington_hikes'
|
5
|
+
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
require_relative '../lib/washington_hikes/version'
|
6
|
+
require_relative '../lib/washington_hikes/cli'
|
7
|
+
require_relative '../lib/washington_hikes/hike'
|
8
|
+
require_relative '../lib/washington_hikes/region'
|
9
|
+
require_relative '../lib/washington_hikes/scraper'
|
@@ -0,0 +1,150 @@
|
|
1
|
+
class WashingtonHikes::CLI
|
2
|
+
attr_accessor :region
|
3
|
+
|
4
|
+
def start
|
5
|
+
puts "\n\nWelcome to Washington Hikes!"
|
6
|
+
puts "\n\nFinding the most popular hikes across Washington..."
|
7
|
+
WashingtonHikes::Hike.create_from_wta
|
8
|
+
@region = "all"
|
9
|
+
welcome
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# Determine if the user wants to find hikes in a region or browse hikes across Washington
|
15
|
+
def welcome
|
16
|
+
puts "\n\nWhat would you like to do?"
|
17
|
+
puts "1. Find the most popular hikes in a specific region of Washington"
|
18
|
+
puts "2. Browse the most popular hikes across Washington"
|
19
|
+
puts "3. Exit the app.\n "
|
20
|
+
puts "Type '1', '2', or '3' to choose."
|
21
|
+
|
22
|
+
input = gets.chomp
|
23
|
+
|
24
|
+
case input
|
25
|
+
when "1"
|
26
|
+
choose_region
|
27
|
+
when "2"
|
28
|
+
choose_hike
|
29
|
+
when "3"
|
30
|
+
exit
|
31
|
+
else
|
32
|
+
welcome
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
# Prompts user to choose a region from a list of regions
|
39
|
+
def choose_region
|
40
|
+
puts "\n\nHere are the regions you can choose from:\n "
|
41
|
+
regions = WashingtonHikes::Region.all # Get list of regions
|
42
|
+
list_regions(regions) # Display list of regions
|
43
|
+
|
44
|
+
puts "\nChoose a region by typing the corresponding number, or type 'menu' to go to the main menu."
|
45
|
+
input = gets.chomp
|
46
|
+
|
47
|
+
if input == "menu" # Returns user to main menu
|
48
|
+
welcome
|
49
|
+
elsif input.to_i.between?(1, regions.size) # ID user-selected region and lets them choose a hike
|
50
|
+
@region = regions[input.to_i - 1]
|
51
|
+
choose_hike
|
52
|
+
else # If input isn't recognized, have user choose a region again
|
53
|
+
choose_region
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
# Lists regions
|
60
|
+
def list_regions(regions)
|
61
|
+
regions.each.with_index(1) do |region,i|
|
62
|
+
puts "#{i}. #{region.name}"
|
63
|
+
puts " #{region.common_landscape_features.join(", ")}"
|
64
|
+
puts " Average Hike Rating: #{region.average_hike_rating}\n "
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
# Prompts users to choose a hike from a list of hikes
|
71
|
+
def choose_hike
|
72
|
+
# Gather list of hikes - either all hikes, or hikes in a specific region
|
73
|
+
if @region == "all"
|
74
|
+
puts "\n\nHere are the most popular hikes in Washington:\n "
|
75
|
+
hikes = WashingtonHikes::Hike.all
|
76
|
+
else
|
77
|
+
puts "\n\nHere are the most popular hikes in the #{@region.name}:\n "
|
78
|
+
hikes = @region.hikes
|
79
|
+
end
|
80
|
+
|
81
|
+
# Lists hikes in designated region
|
82
|
+
list_hikes(hikes)
|
83
|
+
|
84
|
+
puts "\nChoose a hike by typing the corresponding number, or type 'menu' to go to the main menu."
|
85
|
+
input = gets.chomp
|
86
|
+
|
87
|
+
if input == "menu" # Returns user to main menu
|
88
|
+
welcome
|
89
|
+
elsif input.to_i.between?(1, hikes.size) # ID user-selected hike and show them hike details
|
90
|
+
list_hike_details(hikes[input.to_i - 1])
|
91
|
+
@region = hikes[input.to_i - 1].region
|
92
|
+
else # If input isn't recognized, have user choose hike again
|
93
|
+
choose_hike
|
94
|
+
end
|
95
|
+
|
96
|
+
what_next? # Prompt user to take another action after seeing hike details
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
# Lists hikes in selected region
|
102
|
+
def list_hikes(hikes)
|
103
|
+
hikes.each.with_index(1) {|hike,i| puts "#{i}. #{hike.name} -- #{hike.length} miles, #{hike.type} -- #{hike.elevation_gain}"}
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
# Lists details for selected hike
|
109
|
+
def list_hike_details(hike)
|
110
|
+
hike.add_hike_details
|
111
|
+
puts "\n\n----------------------------"
|
112
|
+
puts "\n#{hike.name}"
|
113
|
+
puts "Region: #{hike.region.name}"
|
114
|
+
puts "Length: #{hike.length} miles, #{hike.type}"
|
115
|
+
puts "Elevation Gain: #{hike.elevation_gain}"
|
116
|
+
puts "Rating: #{hike.rating} / 5"
|
117
|
+
puts "Features: #{hike.features.join(", ")}"
|
118
|
+
puts ""
|
119
|
+
puts "#{hike.description}"
|
120
|
+
puts "\n----------------------------\n \n"
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
# Prompts user to take another action after seeing hike details
|
126
|
+
def what_next?
|
127
|
+
puts "\n\nWhat would you like to do next?\n "
|
128
|
+
puts "1. See more popular hikes in this region."
|
129
|
+
puts "2. See popular hikes across Washington."
|
130
|
+
puts "3. Choose a different region."
|
131
|
+
puts "4. Exit the app.\n "
|
132
|
+
puts "Type '1', '2', '3' or '4' to choose."
|
133
|
+
|
134
|
+
input = gets.chomp
|
135
|
+
|
136
|
+
case input
|
137
|
+
when "1"
|
138
|
+
choose_hike # User can choose a hike from the region the current hike is in
|
139
|
+
when "2"
|
140
|
+
@region = "all" # User can choose a hike from all hikes
|
141
|
+
choose_hike
|
142
|
+
when "3"
|
143
|
+
choose_region # User can choose a new region to brose
|
144
|
+
when "4"
|
145
|
+
exit # Exit the app
|
146
|
+
else
|
147
|
+
what_next? # If input isn't recognized, prompt user again
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
3
|
+
class WashingtonHikes::Hike
|
4
|
+
attr_accessor :name, :length, :type, :elevation_gain, :region, :description, :url, :rating, :features
|
5
|
+
@@all = []
|
6
|
+
|
7
|
+
# Initialize a hike with a hash of attributes, and connect hike and region instances
|
8
|
+
def initialize(attributes)
|
9
|
+
attributes.each {|key, value| self.send(("#{key}="), value)}
|
10
|
+
@region.add_hike(self)
|
11
|
+
@@all << self
|
12
|
+
end
|
13
|
+
|
14
|
+
# Create new hike instances with attributes gathered from scraped WTA page
|
15
|
+
def self.create_from_wta
|
16
|
+
hikes = WashingtonHikes::Scraper.scrape_wta_hike_list
|
17
|
+
hikes.each do |hike|
|
18
|
+
hike[:region] = WashingtonHikes::Region.find_or_create_region_by_name(hike[:region])
|
19
|
+
self.new(hike)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# All hikes in class
|
24
|
+
def self.all
|
25
|
+
@@all
|
26
|
+
end
|
27
|
+
|
28
|
+
# Add additional properties to hikes users want to see details on
|
29
|
+
def add_hike_details
|
30
|
+
scraped_details = WashingtonHikes::Scraper.scrape_wta_hike_description(self.url)
|
31
|
+
scraped_details.each {|key, value| self.send(("#{key}="), value)}
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class WashingtonHikes::Region
|
2
|
+
attr_accessor :name, :hikes
|
3
|
+
@@all = []
|
4
|
+
|
5
|
+
# Initializes a region with a name and hikes array
|
6
|
+
def initialize(name)
|
7
|
+
@name = name
|
8
|
+
@hikes = []
|
9
|
+
@@all << self
|
10
|
+
end
|
11
|
+
|
12
|
+
# Find or create a new region by name
|
13
|
+
def self.find_or_create_region_by_name(name)
|
14
|
+
existing = self.all.detect{|region| region.name == name}
|
15
|
+
existing != nil ? existing : self.new(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
# All regions in class
|
19
|
+
def self.all
|
20
|
+
@@all
|
21
|
+
end
|
22
|
+
|
23
|
+
# Add hike to region's 'hikes' array
|
24
|
+
def add_hike(hike)
|
25
|
+
@hikes << hike
|
26
|
+
end
|
27
|
+
|
28
|
+
# Identifies the most common landcape features in a region based on hike features
|
29
|
+
def common_landscape_features
|
30
|
+
# Collect count of each landscape feature from hikes in region
|
31
|
+
feature_list = {}
|
32
|
+
not_landscape = ["Dogs allowed on leash", "Dogs not allowed", "Established campsites", "Good for kids", "Fall foliage"]
|
33
|
+
|
34
|
+
@hikes.each do |hike|
|
35
|
+
hike.features.each do |feature|
|
36
|
+
if not_landscape.include?(feature) == false
|
37
|
+
feature_list[feature] == nil ? feature_list[feature] = 1 : feature_list[feature] += 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Sort feature list by most common and return the top 5 landscape features
|
43
|
+
feature_list.sort_by{|feature,count| count}.reverse.flatten.delete_if{|x| x.is_a?(Integer)}[0..4]
|
44
|
+
end
|
45
|
+
|
46
|
+
# Calculates the average rating of popular hikes in the region
|
47
|
+
def average_hike_rating
|
48
|
+
ratings = @hikes.collect {|hike| hike.rating} # Collect ratings of hikes in region
|
49
|
+
(ratings.sum / ratings.size).round(2) # Return the average rating of hikes in region
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class WashingtonHikes::Scraper
|
2
|
+
# Get HTML for a webpage
|
3
|
+
def self.get_page(url)
|
4
|
+
Nokogiri::HTML(open(url))
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
# Scrape hike attributes from list of hikes on WTA
|
9
|
+
def self.scrape_wta_hike_list
|
10
|
+
number_of_pages = 2 # Number of WTA pages to scrape (they always show 30 hikes / page)
|
11
|
+
hikes = [] # Create an empty erray to shovel hikes into
|
12
|
+
page_index = 0 # 1st hike in WTA list that will be scaped - feeds into URL
|
13
|
+
|
14
|
+
# Iterate through the number of hike pages you wish to scrape
|
15
|
+
number_of_pages.times do
|
16
|
+
url = "https://www.wta.org/go-outside/hikes?b_start:int=#{page_index}"
|
17
|
+
page_of_hikes = get_page(url).css("div#search-result-listing .search-result-item")
|
18
|
+
|
19
|
+
# Collect a hash of hike attributes for each hike on a page
|
20
|
+
page_of_hikes.each do |hike|
|
21
|
+
hike_attributes = {
|
22
|
+
name: hike.css(".item-header span").text.split(" - ")[0].strip,
|
23
|
+
region: hike.css(".item-header h3.region").text.split(" -- ")[0].strip,
|
24
|
+
url: hike.css(".item-header a.listitem-title").attribute("href").value.strip,
|
25
|
+
length: hike.css(".hike-detail .hike-stats .hike-length").size == 0 ? "unknown" : hike.css(".hike-detail .hike-stats .hike-length span").children.text.split(",")[0].split(" ")[0].to_i,
|
26
|
+
type: hike.css(".hike-detail .hike-stats .hike-length").size == 0 ? "unknown" : hike.css(".hike-detail .hike-stats .hike-length span").children.text.split(",")[-1].strip,
|
27
|
+
rating: hike.css(".hike-detail .hike-stats .hike-rating .Rating .AverageRating .star-rating .current-rating").text.split(" ")[0].to_f,
|
28
|
+
features: hike.css(".hike-detail .hike-stats .trip-features").size == 0 ? [] : hike.css(".hike-detail .hike-stats .trip-features")[0].children.css("img").collect{|feature| feature.attribute("title").value},
|
29
|
+
elevation_gain: hike.css(".hike-detail .hike-stats .hike-gain").size == 0 ? "unknown" : hike.css(".hike-detail .hike-stats .hike-gain span").children.text.strip.to_i
|
30
|
+
}
|
31
|
+
hikes << hike_attributes
|
32
|
+
end
|
33
|
+
|
34
|
+
# Update URL index -- WTA always shows 30 hikes / page, starting with page_index
|
35
|
+
page_index += 30
|
36
|
+
end
|
37
|
+
|
38
|
+
# Return an array of hashes, each containing attributes for a scraped hike
|
39
|
+
hikes
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
# Scrape hike details from a hike's webpage
|
44
|
+
def self.scrape_wta_hike_description(url)
|
45
|
+
# Scrape description from hike detail page
|
46
|
+
scraped_details = get_page(url).css("#hike-wrapper")
|
47
|
+
|
48
|
+
# Return a hash with the desired details
|
49
|
+
{description: scraped_details.css("#hike-body-text p").size == 0 ? "" : scraped_details.css("#hike-body-text p")[0].text}
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "washington_hikes/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "washington_hikes"
|
8
|
+
spec.version = WashingtonHikes::VERSION
|
9
|
+
spec.authors = ["Elizabeth Karst"]
|
10
|
+
spec.email = ["efkarst@outlook.com"]
|
11
|
+
|
12
|
+
spec.summary = "Washington hikes lets a user browse and see details on the most popular hikes across Washington state, or from a specific region of the state."
|
13
|
+
spec.homepage = "https://github.com/efkarst/washington-hikes-cli"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
spec.add_development_dependency "pry", "1.1.0"
|
38
|
+
|
39
|
+
spec.add_dependency "nokogiri", "~>1.8"
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: washington_hikes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Elizabeth Karst
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-29 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: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: 1.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.1.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.8'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.8'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- efkarst@outlook.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- ".vscode/settings.json"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- Notes
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- bin/washington-hikes
|
103
|
+
- lib/washington_hikes.rb
|
104
|
+
- lib/washington_hikes/cli.rb
|
105
|
+
- lib/washington_hikes/hike.rb
|
106
|
+
- lib/washington_hikes/region.rb
|
107
|
+
- lib/washington_hikes/scraper.rb
|
108
|
+
- lib/washington_hikes/version.rb
|
109
|
+
- washington_hikes.gemspec
|
110
|
+
homepage: https://github.com/efkarst/washington-hikes-cli
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata:
|
114
|
+
allowed_push_host: https://rubygems.org
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.7.7
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Washington hikes lets a user browse and see details on the most popular hikes
|
135
|
+
across Washington state, or from a specific region of the state.
|
136
|
+
test_files: []
|