nyt_journeys_cli_gem 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 193b4599b181c3557e1dd77e7a606bdce2b17bb2
4
+ data.tar.gz: 16f2908258b67e007286350864a8faef37471d1a
5
+ SHA512:
6
+ metadata.gz: 21fddf483d113d70495542d96e436f3012c15d91b890531d4cea6fcbc79a8b8b9f66aa18ad40f80fd94a08e63c439f9da2d187fb6cdf8ad7581781dcbe19ecc1
7
+ data.tar.gz: 7d2ba06fb0de19dcc339e3df3e1d3c3ccd751dc0dc9917fc8258f559b1ac1acfa9f2ab7bd3947d3c11ade089fcf96aeb08fee829b72a21da261a68a57c0854b2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nyt_journeys.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 lisamarie616
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,27 @@
1
+ # NytJourneys
2
+
3
+ Explore journeys available with NY Times!
4
+
5
+ ## Installation
6
+
7
+ You can install this gem via gem install nyt_journeys_cli_gem. The nyt_journeys CLI will be installed and you can run nyt_journeys to get a list of movies playing now right in your command line.
8
+
9
+ ## Usage
10
+
11
+ Run: nyt_journeys after installing the gem.
12
+
13
+ ## Development
14
+
15
+ 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.
16
+
17
+ 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).
18
+
19
+ ## Contributing
20
+
21
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nyt_journeys. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
22
+
23
+
24
+ ## License
25
+
26
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
27
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nyt_journeys"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "irb"
10
+ IRB.start
data/bin/nyt_journeys ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'now_playing'
4
+
5
+ NytJourneys::CommandLineInterface.new.call
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,139 @@
1
+ class NytJourneys::CommandLineInterface
2
+ def call
3
+ NytJourneys::Data_Generator.new.make_journeys
4
+ start
5
+ end
6
+
7
+ def greeting
8
+ puts ""
9
+ puts "~~*~~*~~*~~ New York Times Journeys ~~*~~*~~*~~"
10
+ puts ""
11
+ puts NytJourneys::Scraper.scrape_quotes.sample
12
+ puts ""
13
+ end
14
+
15
+ def list_journeys
16
+ puts ""
17
+ puts "~~*~~*~~*~~ Available New York Times Journeys ~~*~~*~~*~~"
18
+ puts ""
19
+ NytJourneys::Journeys.all.each.with_index(1) do |journey, index|
20
+ puts "#{index}. #{journey.name}"
21
+ end
22
+ puts ""
23
+ end
24
+
25
+ def navigate_journeys
26
+ list_journeys
27
+ puts ""
28
+ puts "Which journey would you like to learn more about? Enter 1 - #{NytJourneys::Journeys.all.count}."
29
+ puts ""
30
+ puts "Enter 'types' to see journey categories."
31
+ puts "Enter 'exit' to end the program."
32
+ input = gets.downcase.strip
33
+ if input == "types"
34
+ navigate_types
35
+ elsif input.to_i > 0
36
+ if journey = NytJourneys::Journeys.find(input.to_i)
37
+ print_journey(journey)
38
+ end
39
+ end
40
+ end
41
+
42
+ def print_journey(journey)
43
+ puts ""
44
+ puts "~~*~~*~~*~~ #{journey.name} ~~*~~*~~*~~"
45
+ puts "A Journey Focused On #{journey.type}"
46
+ puts ""
47
+ puts journey.description
48
+ puts ""
49
+ puts "From: #{journey.cost}"
50
+ puts ""
51
+ puts "Journey Duration: #{journey.length}"
52
+ puts ""
53
+ puts "Available Dates:"
54
+ puts journey.dates
55
+ puts ""
56
+ puts "Itinerary:"
57
+ puts journey.itinerary
58
+ puts ""
59
+ end
60
+
61
+ def list_types
62
+ puts ""
63
+ puts "~~*~~*~~*~~ Journeys Focused On ~~*~~*~~*~~"
64
+ puts ""
65
+ NytJourneys::Journeys.types.each.with_index(1) do |type, index|
66
+ puts "#{index}. #{type}"
67
+ end
68
+ puts ""
69
+ end
70
+
71
+ def navigate_types
72
+ list_types
73
+ puts ""
74
+ puts "Which type of journey would you like to take? Enter 1 - #{NytJourneys::Journeys.types.count}."
75
+ puts ""
76
+ puts "Enter 'list' to see all journeys."
77
+ puts "Enter 'exit' to end the program."
78
+ input = gets.downcase.strip
79
+ if input == "list"
80
+ navigate_journeys
81
+ elsif input.to_i > 0
82
+ if category = NytJourneys::Journeys.types[input.to_i - 1]
83
+ print_category(category)
84
+ navigate_category(category)
85
+ end
86
+ end
87
+ end
88
+
89
+ def print_category(category)
90
+ puts ""
91
+ puts "~~*~~*~~*~~ Journeys Focused On #{category} ~~*~~*~~*~~"
92
+ puts ""
93
+ NytJourneys::Journeys.find_by_type(category).each.with_index(1) do |journey, index|
94
+ puts "#{index}. #{journey.name}"
95
+ end
96
+ puts ""
97
+ end
98
+
99
+ def navigate_category(category)
100
+ puts ""
101
+ puts "Which journey would you like to learn more about? Enter 1 - #{NytJourneys::Journeys.find_by_type(category).count}."
102
+ puts ""
103
+ puts "Enter 'list' to see all journeys."
104
+ puts "Enter 'types' to see journey categories."
105
+ puts "Enter 'exit' to end the program."
106
+ input = gets.downcase.strip
107
+ if input == "list"
108
+ navigate_journeys
109
+ elsif input == "types"
110
+ navigate_types
111
+ elsif input.to_i > 0
112
+ if journey = NytJourneys::Journeys.find_by_type(category)[input.to_i - 1]
113
+ print_journey(journey)
114
+ end
115
+ end
116
+ end
117
+
118
+ def start
119
+ greeting
120
+ input = nil
121
+ while input != "exit"
122
+ puts ""
123
+ puts "Enter 'list' to see all journeys."
124
+ puts "Enter 'types' to see journey categories."
125
+ puts "Enter 'exit' to end the program."
126
+ puts ""
127
+ input = gets.downcase.strip
128
+ if input == "list"
129
+ navigate_journeys
130
+ elsif input == "types"
131
+ navigate_types
132
+ end
133
+ end
134
+ puts ""
135
+ puts NytJourneys::Scraper.scrape_quotes.sample
136
+ puts ""
137
+ puts "Enjoy the journey!"
138
+ end
139
+ end
@@ -0,0 +1,15 @@
1
+ class NytJourneys::Data_Generator
2
+ BASE_URL = "http://www.nytimes.com/times-journeys/trip-type/"
3
+
4
+ def make_journeys
5
+ type_array = NytJourneys::Scraper.scrape_type_summary_page(BASE_URL)
6
+
7
+ trip_array = type_array.collect do |type|
8
+ NytJourneys::Scraper.scrape_type_detail_page(type)
9
+ end
10
+ trip_array.flatten!
11
+
12
+ NytJourneys::Journeys.create_from_collection(trip_array)
13
+ end
14
+
15
+ end
@@ -0,0 +1,61 @@
1
+ class NytJourneys::Journeys
2
+ attr_accessor :name, :url, :type, :description
3
+
4
+ @@all = []
5
+
6
+ def initialize(trip_hash)
7
+ trip_hash.each {|k,v| self.send("#{k}=",v)}
8
+ @@all << self
9
+ end
10
+
11
+ def self.create_from_collection(trip_array)
12
+ trip_array.each {|trip| self.new(trip)}
13
+ end
14
+
15
+ def self.all
16
+ @@all
17
+ end
18
+
19
+ def self.find(id)
20
+ all[id - 1]
21
+ end
22
+
23
+ def self.types
24
+ all.collect {|journey| journey.type}.uniq
25
+ end
26
+
27
+ def self.find_by_type(type)
28
+ all.select {|journey| journey.type == type}
29
+ end
30
+
31
+ def doc
32
+ Nokogiri::HTML(open(url))
33
+ end
34
+
35
+ def description
36
+ description = ""
37
+ doc.css("div.trip-description p").each do |paragraph|
38
+ description << "#{paragraph.text} "
39
+ end
40
+ description = description.strip.gsub(/(\n)/," ")
41
+ end
42
+
43
+ def cost
44
+ cost ||= doc.css("div.price p").text[/\$\S+/]
45
+ end
46
+
47
+ def length
48
+ length ||= doc.css("div.itinerary-info > p").text.strip[/.+s/]
49
+ end
50
+
51
+ def dates
52
+ dates ||= doc.css("div.departures a.departure-link").collect {|date_range| date_range.text}
53
+ end
54
+
55
+ def itinerary
56
+ itinerary ||= doc.css("div.primary-information").collect do |day|
57
+ "#{day.css("div.day-number").text} - #{day.css("h3.day-title").text}"
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,51 @@
1
+ class NytJourneys::Scraper
2
+
3
+ # type_name: .css("h3.trip-type-list-title").text
4
+ # type_url: .css("a.view-all-link").attribute("href").value
5
+ def self.scrape_type_summary_page(summary_url)
6
+ type_summary = Nokogiri::HTML(open(summary_url))
7
+ types = []
8
+ type_summary.css("div.trip-type-listings").each do |type|
9
+ type_hash = {}
10
+ type_hash[:type_name] = type.css("h3.trip-type-list-title").text
11
+ type_hash[:type_url] = type.css("a.view-all-link").attribute("href").value
12
+ types << type_hash
13
+ end
14
+ types # an array of type hashes with type_name and type_url properties
15
+ end
16
+
17
+ # trip_name: .css("h2.item-title").text
18
+ # trip_url: .css.attribute("href").value
19
+ def self.scrape_type_detail_page(types_hash)
20
+ type_details = Nokogiri::HTML(open(types_hash.values[1]))
21
+ trips =[]
22
+ type_details.css("li.journey-list-item > a").each do |trip|
23
+ trips_hash = {}
24
+ trips_hash[:name] = trip.css("h2.item-title").text
25
+ trips_hash[:url] = trip.attribute("href").value
26
+ trips_hash[:type] = types_hash.values[0]
27
+ trips << trips_hash
28
+ end
29
+ trips # an array of trip hashes with name, url, and type properties
30
+ end
31
+
32
+ # quote: quotations_page.css("dt.quote"), .css("a").text
33
+ # author: quotations_page.css("dd.author), .css("a").text
34
+ def self.scrape_quotes(quotes_url="http://www.quotationspage.com/search.php3?homesearch=journey&page=1")
35
+ quotations_page = Nokogiri::HTML(open(quotes_url))
36
+ quotes = []
37
+ quotations_page.css("dt.quote").each do |quote|
38
+ item = "#{quote.css("a").text}"
39
+ quotes << item
40
+ end
41
+ authors = []
42
+ quotations_page.css("dd.author").each do |author|
43
+ item = "#{author.css("a")[4].text}"
44
+ authors << item
45
+ end
46
+ quotes.map.with_index do |quote, index|
47
+ "#{quote} ~ #{authors[index]}"
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,3 @@
1
+ module NytJourneys
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'open-uri'
2
+ require 'pry'
3
+ require 'nokogiri'
4
+
5
+ require "nyt_journeys/command_line_interface"
6
+ require "nyt_journeys/data_generator"
7
+ require "nyt_journeys/journeys"
8
+ require "nyt_journeys/scraper"
9
+ require "nyt_journeys/version"
10
+
11
+ module NytJourneys
12
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nyt_journeys/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nyt_journeys_cli_gem"
8
+ spec.version = NytJourneys::VERSION
9
+ spec.authors = ["lisamarie616"]
10
+ spec.email = ["lisamarie616@gmail.com"]
11
+
12
+ spec.summary = %q{NYT Journeys}
13
+ spec.description = %q{Explore journeys available with NY Times.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($\)
18
+ spec.executables = ["nyt_journeys"]
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib", "lib/nyt_journeys"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "nokogiri"
26
+ spec.add_development_dependency "pry"
27
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe NytJourneys do
4
+ it 'has a version number' do
5
+ expect(NytJourneys::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(true).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'nyt_journeys'
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nyt_journeys_cli_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - lisamarie616
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-28 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: '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: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Explore journeys available with NY Times.
84
+ email:
85
+ - lisamarie616@gmail.com
86
+ executables:
87
+ - nyt_journeys
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CODE_OF_CONDUCT.md
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/nyt_journeys
101
+ - bin/setup
102
+ - lib/nyt_journeys.rb
103
+ - lib/nyt_journeys/command_line_interface.rb
104
+ - lib/nyt_journeys/data_generator.rb
105
+ - lib/nyt_journeys/journeys.rb
106
+ - lib/nyt_journeys/scraper.rb
107
+ - lib/nyt_journeys/version.rb
108
+ - nyt_journeys.gemspec
109
+ - spec/nyt_journeys_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: ''
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ - lib/nyt_journeys
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.5.1
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: NYT Journeys
136
+ test_files:
137
+ - spec/nyt_journeys_spec.rb
138
+ - spec/spec_helper.rb