trail-info-cli-gem 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4fef9aa1f241f91d727392ab65b466ce9084d481
4
+ data.tar.gz: d065f1ee17fd6526d7241641072812152f2a7bb3
5
+ SHA512:
6
+ metadata.gz: 1dd13ce0f70ae05b205d183d1b177ff325fc39f9dd9eb1c3e57fc95974f52b2b965dbc96f1583d122a4d35a999321fa2f6cf1e39c9e35b72ce3c0bb4388275ec
7
+ data.tar.gz: 7724396ab642b5dfa0680fb31d9d58b33c45e2b89934665951f0958862f51fa0724223e28967077a4df2d47f4c3f284dd67b9719ffd14802fe9052590f972307
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
Binary file
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trail_info.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Traci7822
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.
@@ -0,0 +1,39 @@
1
+ # TrailInfo
2
+
3
+ This TrailInfo CLI GEM is programmed to allow the user to select a state and then display available trails in that state from TrailLink.com. Users are then able to select a trail from that list to see further details about the trail.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'trail_info'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install trail_info
20
+
21
+ ## Usage
22
+
23
+ To use TrailInfo, run ./bin/trail_info in your terminal. A list of states will be displayed, select one by number and hit enter to bring up trails in that state. When the trail list populates, enter a trail number and hit enter to see further details on the selected trail. Use menu commands to navigate back to the start.
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Traci7822/trail_info.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "trail_info"
5
+
6
+
7
+ require "irb"
8
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ require_relative "../lib/trail_info"
5
+
6
+
7
+ TrailInfo::CLI.new.call
8
+
9
+
@@ -0,0 +1,9 @@
1
+ require_relative "trail_info/version"
2
+ require_relative 'trail_info/CLI'
3
+ require_relative 'trail_info/trail'
4
+ require_relative 'trail_info/states'
5
+ require_relative 'trail_info/scraper'
6
+ require 'Nokogiri'
7
+ require 'open-uri'
8
+
9
+
@@ -0,0 +1,87 @@
1
+ class TrailInfo::CLI
2
+
3
+ @@STATE_NAMES = {AL: 'ALABAMA',
4
+ AK: 'ALASKA','AZ'=>'ARIZONA','AR'=>'ARKANSAS','CA'=>'CALIFORNIA','CO'=>'COLORADO','CT'=>'CONNECTICUT',
5
+ 'DE'=>'DELAWARE','DC'=>'DISTRICT OF COLUMBIA','FL'=>'FLORIDA','GA'=>'GEORGIA','HI'=>'HAWAII','ID'=>'IDAHO',
6
+ 'IL'=>'ILLINOIS','IN'=>'INDIANA','IA'=>'IOWA', 'KS'=>'KANSAS', 'KY'=>'KENTUCKY', 'LA'=>'LOUISIANA', 'ME'=>'MAINE',
7
+ 'MD'=>'MARYLAND', 'MA'=>'MASSACHUSETTS', 'MI'=>'MICHIGAN', 'MN'=>'MINNESOTA', 'MS'=>'MISSISSIPPI', 'MO'=>'MISSOURI',
8
+ 'MT'=>'MONTANA', 'NE'=>'NEBRASKA', 'NV'=>'NEVADA', 'NH'=>'NEW HAMPSHIRE', 'NJ'=>'NEW JERSEY', 'NM'=>'NEW MEXICO',
9
+ 'NY'=>'NEW YORK', 'NC'=>'NORTH CAROLINA', 'ND'=>'NORTH DAKOTA', 'OH'=>'OHIO', 'OK'=>'OKLAHOMA', 'OR'=>'OREGON',
10
+ 'PA'=>'PENNSYLVANIA', 'RI'=>'RHODE ISLAND', 'SC'=>'SOUTH CAROLINA', 'SD'=>'SOUTH DAKOTA', 'TN'=>'TENNESSEE',
11
+ 'TX'=>'TEXAS', 'UT'=>'UTAH', 'VT'=>'VERMONT', 'VA'=>'VIRGINIA', 'WA'=>'WASHINGTON', 'WV'=>'WEST VIRGINIA',
12
+ 'WI'=>'WISCONSIN', 'WY'=>'WYOMING'}
13
+
14
+ def call
15
+ puts "Welcome to Trail Finder!"
16
+ menu
17
+ end
18
+
19
+ def menu
20
+ puts "Enter which state number you'd like to find a trail in and press enter or type 'exit' to exit the program.\n\n"
21
+ list_states
22
+ end
23
+
24
+ def list_states
25
+ @@STATE_NAMES.each.with_index(1) do |state_name, index|
26
+ puts "#{index}. #{state_name[1]}"
27
+ end
28
+ state_input
29
+ end
30
+
31
+ def state_input #allows user to select which state to view trails in
32
+ selection = gets.strip.downcase
33
+ list_trails(selection)
34
+ end
35
+
36
+ def list_trails(state_number) #checks input to determine whether to list trails or exit
37
+ if state_number.to_i.between?(1, 51)
38
+ initiate_trails_report(state_number.to_i)
39
+ elsif
40
+ state_number == "exit"
41
+ exit
42
+ else
43
+ puts "Please enter a valid number between 1 - 51."
44
+ state_input
45
+ end
46
+ end
47
+
48
+ def initiate_trails_report(state_number) #Writes state selection, initiates new state instance, lists states trails
49
+ puts "You've selected #{state_number}. #{@@STATE_NAMES.values[state_number - 1]}. Here are the available trails in #{@@STATE_NAMES[state_number]} according to TrailLink.com. This may take a moment to load.\n \n"
50
+ initiate_state(state_number)
51
+ list_trails_report
52
+ end
53
+
54
+ def initiate_state(state_number) #creates new state instance
55
+ TrailInfo::State.new(@@STATE_NAMES.values[state_number - 1], @@STATE_NAMES.keys[state_number - 1])
56
+ end
57
+
58
+ def list_trails_report #populates trail list for selected state and asks for input for more details, reset, or exit
59
+ TrailInfo::State.trail_list
60
+ puts "\nPlease select a trail number to see more details, enter 'reset' to go back to the main menu, or 'exit' to exit the program."
61
+ exit_input
62
+ end
63
+
64
+ def exit_input #takes user input and displays trail description, returns user to previous menus, or exits
65
+ @trail_array = TrailInfo::State.all
66
+ max_trail_number = @trail_array[0].trails.length
67
+ input = gets.strip.downcase
68
+ @trail_number = input.to_i
69
+ if input.to_i.between?(1, max_trail_number)
70
+ trail_description(@trail_array, @trail_number)
71
+ else
72
+ if input == 'back' ? list_trails_report : if input == "reset" ? TrailInfo::State.clear_all && call : (input == "exit" ? exit : (puts "I'm sorry, I don't understand. Please try again." && exit_input))
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ def trail_description(trail_array, trail_number) #Writes detailed trail information and asks for user input
79
+ trail = trail_array[0].trails[trail_number]
80
+ puts "#{trail.name} | Length: #{trail.length} | Surface: #{trail.surface}|"
81
+ puts "#{trail.synopsis}"
82
+ puts "\nFor more information visit: #{trail.url}"
83
+ puts "\nEnter 'back' to return to the list of trails, 'reset' to go back to the main menu, or 'exit' to exit the program."
84
+ exit_input
85
+ end
86
+ end
87
+
@@ -0,0 +1,6 @@
1
+ class TrailInfo::Rate
2
+
3
+ attr_acessor :rating
4
+
5
+
6
+ end
@@ -0,0 +1,58 @@
1
+ class TrailInfo::Scraper
2
+
3
+ def self.create_trails(state_code) #Initiates state scrape
4
+ scrape_state_guides(state_code)
5
+ end
6
+
7
+ def self.scrape_state_guides(state_code) #Scrapes state site, collects and returns trail information
8
+ @state_scrape = Nokogiri::HTML(open("http://www.traillink.com/stateactivity/#{state_code}-hiking-trails.aspx"))
9
+ scrape_attributes
10
+ @trail_array
11
+ end
12
+
13
+ def self.scrape_attributes #Scrapes trail attributes and collects to trail_array
14
+ @trail_array = []
15
+ @state_scrape.css(".activityTrail").css(".trailmeta").each do |state_scrape|
16
+ scrape_trail_attributes(state_scrape)
17
+ @trail_array << @new_trail
18
+ end
19
+ end
20
+
21
+ def self.scrape_trail_attributes(state_scrape) #Scrapes trail details
22
+ @new_trail = {}
23
+ @new_trail["synopsis"] = scrape_synopsis(state_scrape)
24
+ @new_trail["name"] = scrape_trail_name(state_scrape)
25
+ @new_trail["url"] = scrape_url(state_scrape)
26
+ state_scrape.css("p").each do |trail_section|
27
+ scrape_trail_length_and_surface(trail_section)
28
+ @new_trail
29
+ end
30
+ end
31
+
32
+ def self.scrape_trail_name(state_scrape) #Scrapes trail name
33
+ state_scrape.css("a").text.split.join(" ") unless state_scrape.css("a").text.split.join(" ") == ""
34
+ end
35
+
36
+ def self.scrape_trail_length_and_surface(trail_section) #Scrapes trail length and surface information
37
+ if trail_section.text.include?("miles") ? @new_trail["length"] = [trail_section.text.split[3], trail_section.text.split[4]].join(" ") : @new_trail["length"] = ""
38
+ end
39
+
40
+ if trail_section.text.include?("Surface:")
41
+ if trail_section.text.split[7] == nil ? @new_trail["surface"] = trail_section.text.split[6] : @new_trail["surface"] = [trail_section.text.split[6], trail_section.text.split[7].gsub(/,/, "")].join(" ")
42
+ end
43
+ else
44
+ @new_trail["surface"] = ""
45
+ end
46
+ @new_trail
47
+ end
48
+
49
+ def self.scrape_synopsis(state_scrape) #Scrapes trail synopsis
50
+ @state_synopsis = state_scrape.css(".synopsis").text.strip
51
+ end
52
+
53
+ def self.scrape_url(state_scrape) #Scrapes trail url
54
+ path = state_scrape.css("a").attribute("href").value
55
+ state_url = "http://www.traillink.com#{path}"
56
+ end
57
+
58
+ end
@@ -0,0 +1,35 @@
1
+ class TrailInfo::State
2
+
3
+ attr_accessor :name, :trails
4
+ @@all = []
5
+
6
+ def initialize(name, state_code) #Creates new state instance and initializes scraping and new trail instances
7
+ @name = name
8
+ @trails = []
9
+ TrailInfo::Scraper.create_trails(state_code).each do |trail|
10
+ @trails << TrailInfo::Trail.new(self, trail)
11
+ end
12
+ @@all << self
13
+ end
14
+
15
+ def self.all #returns all trails for state instance
16
+ @@all
17
+ end
18
+
19
+ def self.clear_all #clears trails for state instance
20
+ @@all.clear
21
+ end
22
+
23
+ def self.trail_list #Writes list of states trails
24
+ @trail_list = []
25
+ @@all[0].trails.each.with_index(1) do |trail, i|
26
+ trail_description = "#{i}. #{trail.name} | Length: #{trail.length} | Surface: #{trail.surface}|"
27
+ puts trail_description
28
+ @trail_list << trail_description
29
+ end
30
+ @trail_list
31
+ end
32
+
33
+ end
34
+
35
+
@@ -0,0 +1,22 @@
1
+ class TrailInfo::Trail
2
+
3
+ attr_accessor :name, :length, :surface, :state, :synopsis, :url
4
+
5
+ @@all = []
6
+
7
+ def initialize(state, trail_attributes) #Creates new trail instance
8
+ trail_attributes.each do |attribute_name, attribute_value|
9
+ self.send("#{attribute_name}=", attribute_value)
10
+ end
11
+ save
12
+ end
13
+
14
+ def save #saves trail instance
15
+ @@all << self
16
+ end
17
+
18
+ def self.all #returns all trail instances
19
+ @@all
20
+ end
21
+
22
+ end
@@ -0,0 +1,3 @@
1
+ module TrailInfo
2
+ VERSION = "0.1.4"
3
+ end
data/notes ADDED
@@ -0,0 +1,24 @@
1
+
2
+ http://www.traillink.com/stateactivity/al-hiking-trails.aspx
3
+
4
+ Future ideas:
5
+ -find by name
6
+ -add all cities
7
+ -adds detail option for each trail
8
+
9
+ for added searchability:
10
+ def self.print_all
11
+ all.each_with_index do |trail, index|
12
+ puts "#{i}. #{trail.name} | Length: #{trail.length} | Surface: #{trail.surface}|"
13
+ end
14
+ end
15
+
16
+ def self.trails_by_state(state)
17
+ trail_list = []
18
+ self.all.each do |trail|
19
+ if trail.state.name == selected_state.name
20
+ trail_list << trail
21
+ end
22
+ end
23
+ end
24
+
data/spec.md ADDED
@@ -0,0 +1,10 @@
1
+ # Specifications for the CLI Assessment
2
+
3
+ Specs:
4
+ - [x] Have a CLI for interfacing with the application
5
+ -bin file executes from terminal
6
+ - [x] Pull data from an external source
7
+ -data is scraped with nokogiri from TrailLink.com
8
+ - [x] Implement both list and detail views
9
+ -Selection of a state populates a trail list for that state, selection of a trail from that list populates details
10
+
Binary file
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trail_info/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trail-info-cli-gem"
8
+ spec.version = TrailInfo::VERSION
9
+ spec.authors = ["Traci7822"]
10
+ spec.email = ["tracir@gmail.com"]
11
+
12
+ spec.summary = %q{short summary}
13
+ spec.description = %q{longer description}
14
+ spec.homepage = "https://github.com/Traci7822/trail-info-cli-gem"
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'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.executables = ["trail_info"]
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+
32
+ spec.add_dependency "nokogiri"
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trail-info-cli-gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Traci7822
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-23 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: longer description
56
+ email:
57
+ - tracir@gmail.com
58
+ executables:
59
+ - trail_info
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - 2016-08-13 13-49-01.mp4
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - bin/trail_info
72
+ - lib/trail_info.rb
73
+ - lib/trail_info/CLI.rb
74
+ - lib/trail_info/rate.rb
75
+ - lib/trail_info/scraper.rb
76
+ - lib/trail_info/states.rb
77
+ - lib/trail_info/trail.rb
78
+ - lib/trail_info/version.rb
79
+ - notes
80
+ - spec.md
81
+ - trail_info-0.1.0.gem
82
+ - trail_info.gemspec
83
+ homepage: https://github.com/Traci7822/trail-info-cli-gem
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.5.1
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: short summary
107
+ test_files: []