coming_soon 0.2.2 → 0.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 079b05a821ba026841779a3b74cb2b379d54d971
4
- data.tar.gz: 3c342151087826f23deb6da51162fed2cc6a6c68
3
+ metadata.gz: 08c88ebbb3279d43877e170875e6d261281d1c92
4
+ data.tar.gz: 3392a679a7a4010228b6cc261ff82d44efd866bc
5
5
  SHA512:
6
- metadata.gz: 45701e5b0462c6b98b60b9cdaca1e172389da5ae0f80d100634a73c73152febdc1949fe4f9ba3fa958e71038e641480868a2d30788dcbce5c40eafdf1f527c34
7
- data.tar.gz: a11b964436ed5b4046b6b8bfa7fe61f587003bbd878aefc66d25e4d44e11260dfa47a25386be175c656d3ffa37b789ed2fd3f7be397efd5230b867b2bf44e802
6
+ metadata.gz: d10e89ef02ff35414ba6ea6ea1158770fbba2c44682cb37066bdd92cc883d0aafb861cfdebdeddd8c5daf407d7487b53267b7c89900a5fe6eb7b67bc8288fb04
7
+ data.tar.gz: 605fbf0797deaf107d3b6829ac88d04c49b65edd8c7199640157ef0a166b4958bb2adb4123fa50640d3f85dcdea9b37e89bdb8d7d2ab46dc55c1fa6dd01858e6
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+
@@ -0,0 +1,2 @@
1
+ 2.3.1
2
+
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
6
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coming_soon.gemspec
4
+ gemspec
@@ -0,0 +1,40 @@
1
+
2
+ # Coming Soon
3
+
4
+ This Ruby Gem provides a CLI to view movies coming soon and also allows the user to select specific movies to view further details on.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'coming_soon'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install coming_soon
21
+
22
+ ## Usage
23
+
24
+ Type the below and follow the on screen prompts
25
+
26
+ $ coming-soon
27
+
28
+ ## Development
29
+
30
+ 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.
31
+
32
+ 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).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/terryblue99/coming_soon.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the MIT License.
@@ -0,0 +1,7 @@
1
+
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "coming_soon"
5
+
6
+ ComingSoon::CLI.new.call
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "coming_soon"
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
@@ -0,0 +1,9 @@
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
9
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'coming_soon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "coming_soon"
8
+ spec.version = ComingSoon::VERSION
9
+ spec.authors = ["Terry Blue"]
10
+ spec.email = ["terryblue@comcast.net"]
11
+
12
+ spec.summary = "Movies Coming Soon"
13
+ spec.description = "Provides details of movies coming soon"
14
+ spec.homepage = "https://rubygems.org/gems/coming_soon"
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = ['coming-soon']
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.12"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "pry", ">= 0"
25
+ spec.add_dependency "nokogiri", ">= 0"
26
+ end
@@ -0,0 +1,6 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ require_relative '../lib/coming_soon/version'
5
+ require_relative '../lib/coming_soon/movie'
6
+ require_relative '../lib/coming_soon/cli'
@@ -0,0 +1,2 @@
1
+
2
+ require_relative '../config/environment'
@@ -0,0 +1,72 @@
1
+ class ComingSoon::CLI
2
+
3
+ def call
4
+ get_and_list_movies
5
+
6
+ menu_selection
7
+ end
8
+
9
+ def get_and_list_movies
10
+ puts ''
11
+ puts ' **********************'
12
+ puts ' * Movies Coming Soon *'
13
+ puts ' * -------------- *'
14
+ puts ' * Please wait! *'
15
+ puts ' **********************'
16
+ puts ''
17
+
18
+ @movies = ComingSoon::Movie.movies
19
+
20
+ @movies.each.with_index(1) do |movie, i|
21
+ puts "#{i}. #{movie.name} - #{movie.start_date}"
22
+ end
23
+ end
24
+
25
+ def list_saved_movies
26
+ puts ''
27
+ puts ' **********************'
28
+ puts ' * Movies Coming Soon *'
29
+ puts ' **********************'
30
+ puts ''
31
+
32
+ @movies.each.with_index(1) do |movie, i|
33
+ puts "#{i}. #{movie.name} - #{movie.start_date}"
34
+ end
35
+ end
36
+
37
+ def menu_selection
38
+ input = ''
39
+
40
+ while input != 'exit'
41
+ puts ''
42
+ puts 'You may enter a movie number for more details or "list" to see the menu again or "exit"'
43
+
44
+ input = gets.strip
45
+
46
+ if input.to_i > 0 && input.to_i < @movies.size+1
47
+ puts "* #{@movies[input.to_i - 1].name} - #{@movies[input.to_i - 1].start_date} *"
48
+ puts @movies[input.to_i - 1].synopsis
49
+ elsif input == 'list'
50
+ list_saved_movies
51
+ elsif input == 'exit'
52
+ goodbye
53
+ else
54
+ puts 'Invalid selection!'
55
+ menu_selection
56
+ end
57
+ end
58
+ end
59
+
60
+ def goodbye
61
+ puts ''
62
+ puts ' *************************'
63
+ puts ' * Thank you and goodbye *'
64
+ puts ' * ----------------- *'
65
+ puts ' * Come back soon! *'
66
+ puts ' *************************'
67
+ puts ''
68
+
69
+ exit
70
+ end
71
+
72
+ end
@@ -0,0 +1,66 @@
1
+
2
+ class ComingSoon::Movie
3
+ attr_accessor :name, :start_date, :url, :synopsis
4
+
5
+ def self.movies
6
+
7
+ self.scrape_movies
8
+
9
+ @movies
10
+
11
+ end
12
+
13
+ def self.scrape_movies
14
+
15
+ doc = Nokogiri::HTML(open("http://www.fandango.com/moviescomingsoon"))
16
+ # name: doc.css("li.visual-item a.visual-title").text.strip
17
+ # start_date: doc.css("li.visual-item span").text
18
+ # url: doc.css("li.visual-item a").attribute("href").value
19
+
20
+ movie_list = doc.css("li.visual-item")
21
+ @movies = []
22
+ count = 1
23
+
24
+ movie_list.each do |movie|
25
+ @soon = self.new
26
+ @soon.name = movie.css("a.visual-title").text.strip
27
+ @soon.start_date = movie.css("span").text
28
+ @soon.url = movie.css("a").attribute("href").value
29
+
30
+ self.scrape_synopsis
31
+
32
+ @movies << @soon
33
+
34
+ count+=1
35
+ if count > 20 # Displays only 20 movies
36
+ break
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ def self.scrape_synopsis
43
+
44
+ redirect_failed = false
45
+
46
+ begin
47
+ @doc_synop1 = Nokogiri::HTML(open(@soon.url)) # Uses the HTTP 'movieoverview' url
48
+ rescue
49
+ redirect_failed = true # An HTTP to HTTPS redirect failed
50
+ end
51
+
52
+ if !@doc_synop1.css("a.movie-synopsis-link").any? && !redirect_failed &&
53
+ @doc_synop1.css("span#SynopsisTextLabel").any?
54
+ # If not a redirect failure and a READ FULL SYNOPSIS link is not
55
+ # present and any text is available, use the text for the synopsis
56
+ @soon.synopsis = @doc_synop1.css("span#SynopsisTextLabel").text
57
+ else
58
+ # scrape the synopsis using the HTTP 'plotsummary' url
59
+ synop_url = @soon.url.sub(/movieoverview/, 'plotsummary')
60
+ doc_synop2 = Nokogiri::HTML(open(synop_url))
61
+ @soon.synopsis = doc_synop2.css("p.subpage-descriptive-content").text
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,4 @@
1
+
2
+ module ComingSoon
3
+ VERSION = "0.2.3"
4
+ end
@@ -0,0 +1,48 @@
1
+
2
+ Coming Soon Gem
3
+
4
+ 1. Plan the gem, imagine the interface
5
+ 2. Start with the project structure - google:
6
+ how to build a gem
7
+ make a gem using bundler (e.g bundle gem daily_deal); - watch the video
8
+ how to build a cli gem
9
+ 3. Start with the entry point - the file run => bin/coming-soon
10
+ #!/usr/bin/env ruby
11
+ require ‘bundler/setup’
12
+ require ‘coming_soon’
13
+ ComingSoon::CLI.new.call
14
+ environment file => lib/coming_soon.rb
15
+ require_relative '../config/environment'
16
+ ../config/environment
17
+ require_relative ‘./coming_soon /version’
18
+ require_relative ‘./coming_soon /movies’
19
+ require_relative ‘./coming_soon /cli’
20
+ 4. Force that to build the CLI interface => lib/coming_soon /cli.rb => ComingSoon::CLI
21
+ 5. Stub out the interface: list_movies => scrape data
22
+ menu => display menu of movies
23
+ goodbye => say goodbye
24
+
25
+ 6. Start making things real
26
+ 7. Discover objects
27
+ 8. Program
28
+
29
+ Example:
30
+
31
+ A command line interface for movies coming soon, starting with Fandango
32
+
33
+ • User types coming-soon
34
+ • Show a list of movies
35
+
36
+ 1. Guardians of the Galaxy Vol 2 – May 5
37
+ 2. The Lovers - May 5
38
+
39
+ Which movie do you want to learn more about?
40
+
41
+ 1
42
+
43
+ What is a movie?
44
+
45
+ • A movie has a name
46
+ • A deal has a URL
47
+ • A movie has a start date
48
+ • A movie has a synopsis
data/spec.md ADDED
@@ -0,0 +1,30 @@
1
+
2
+ # Specifications for the CLI Assessment
3
+
4
+ Specs:
5
+ - [x] Have a CLI for interfacing with the application
6
+ ComingSoon::CLI
7
+ get_and_list_movies => scrape data
8
+ menu_selection => display menu of movies
9
+ list_saved_movies => re-list movies
10
+ goodbye => say goodbye
11
+ - [x] Pull data from an external source
12
+ Scrape and save the data using nokogiri and open-uri
13
+ ComingSoon::Movie
14
+ self.scrape_movies => scrape movies
15
+ name, start_date, url
16
+ self.scrape_synopsis => scrape Overview
17
+ synopsis
18
+ - [x] Implement both list and detail views
19
+ - User types coming-soon
20
+ - Show a numbered list of movies
21
+ - display 'You may enter a movie number for more details or "list" to see the menu again or "exit"'
22
+ - if a number between 1 and the number of the last movie in the list
23
+ display the movie name followed by a synopsis of the movie
24
+ - if 'list'
25
+ display the saved list of movies
26
+ - if 'exit'
27
+ exit the application
28
+ - else
29
+ display 'Invalid selection!'
30
+ re-display ''You may enter a movie number for more details or "list" to see the menu again or "exit"''
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coming_soon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Terry Blue
@@ -83,10 +83,29 @@ dependencies:
83
83
  description: Provides details of movies coming soon
84
84
  email:
85
85
  - terryblue@comcast.net
86
- executables: []
86
+ executables:
87
+ - coming-soon
87
88
  extensions: []
88
89
  extra_rdoc_files: []
89
- files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".ruby-version"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - README.md
97
+ - Rakefile
98
+ - bin/coming-soon
99
+ - bin/console
100
+ - bin/setup
101
+ - coming_soon.gemspec
102
+ - config/environment.rb
103
+ - lib/coming_soon.rb
104
+ - lib/coming_soon/cli.rb
105
+ - lib/coming_soon/movie.rb
106
+ - lib/coming_soon/version.rb
107
+ - notes.md
108
+ - spec.md
90
109
  homepage: https://rubygems.org/gems/coming_soon
91
110
  licenses:
92
111
  - MIT