rwflicks 1.0.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/bin/flicks +41 -0
- data/bin/flicks.rb +40 -0
- data/bin/movie_rankings.csv +4 -0
- data/bin/movies.csv +3 -0
- data/bin/super_hero_movies.csv +3 -0
- data/lib/flicks/Rankable.rb +26 -0
- data/lib/flicks/files.rb +13 -0
- data/lib/flicks/movie.rb +59 -0
- data/lib/flicks/movie3d.rb +26 -0
- data/lib/flicks/playlist.rb +78 -0
- data/lib/flicks/snack_bar.rb +22 -0
- data/lib/flicks/waldorf_and_statler.rb +21 -0
- data/spec/flicks/movie_spec.rb +70 -0
- data/spec/flicks/playlist_spec.rb +36 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a4b27394bcfb346d45d0e9935838a9fe229f9079
|
4
|
+
data.tar.gz: 0cb756781b5972e7de6f89f1e6daeef11951b956
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ee409d20d1cc735d14ff8067ead29e2b01f7be68ed75426fbca70e93655b22b870ef4fb2a67c2f0a65b263100c9459d981774cba32f10f8387f01b634d399af
|
7
|
+
data.tar.gz: 9abbfff87a3eaac19dd897c2859f737df03d3d2f5254126f17b4e83945e783a7830e70c8629612171b261a6d5c102b544f4cab5a2e64ecdd06dba649299c1e7d
|
data/bin/flicks
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/flicks/playlist'
|
3
|
+
require_relative '../lib/flicks/movie3d'
|
4
|
+
|
5
|
+
movie1 = Flicks::Movie.new("goonies", 10)
|
6
|
+
movie2 = Flicks::Movie.new("ghostbusters", 9)
|
7
|
+
movie3 = Flicks::Movie.new("goldfinger")
|
8
|
+
|
9
|
+
playlist1 = Flicks::Playlist.new("Kermit")
|
10
|
+
default_movie_file = File.join(File.dirname(__FILE__), 'movies.csv')
|
11
|
+
playlist1.load(ARGV.shift || default_movie_file)
|
12
|
+
movie3d = Flicks::Movie3D.new('glee', 5, 20)
|
13
|
+
playlist1.add_movie(movie3d)
|
14
|
+
loop do
|
15
|
+
puts "\nHow many viewings? ('quit' to exit)"
|
16
|
+
answer = gets.chomp.downcase
|
17
|
+
case answer
|
18
|
+
when /^\d+$/
|
19
|
+
playlist1.play(answer.to_i)
|
20
|
+
when 'quit', 'exit'
|
21
|
+
playlist1.print_stats
|
22
|
+
break
|
23
|
+
else
|
24
|
+
puts "Please enter a number or 'quit'"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
playlist1.save
|
29
|
+
# puts "Enjoy your #{answer} viewings..."
|
30
|
+
# playlist1.play(answer.to_i)
|
31
|
+
|
32
|
+
#playlist1.print_stats
|
33
|
+
|
34
|
+
# playlist2 = Playlist.new("Fozzie")
|
35
|
+
# playlist2.add_movie(movie3)
|
36
|
+
|
37
|
+
# movie4 = Movie.new("gemlins", 15)
|
38
|
+
# playlist2.add_movie(movie4)
|
39
|
+
# playlist2.play(3)
|
40
|
+
# playlist2.print_stats
|
41
|
+
|
data/bin/flicks.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative '../lib/flicks/playlist'
|
2
|
+
require_relative '../lib/flicks/movie3d'
|
3
|
+
|
4
|
+
movie1 = Flicks::Movie.new("goonies", 10)
|
5
|
+
movie2 = Flicks::Movie.new("ghostbusters", 9)
|
6
|
+
movie3 = Flicks::Movie.new("goldfinger")
|
7
|
+
|
8
|
+
playlist1 = Flicks::Playlist.new("Kermit")
|
9
|
+
default_movie_file = File.join(File.dirname(__FILE__), 'movies.csv')
|
10
|
+
playlist1.load(ARGV.shift || default_movie_file)
|
11
|
+
movie3d = Flicks::Movie3D.new('glee', 5, 20)
|
12
|
+
playlist1.add_movie(movie3d)
|
13
|
+
loop do
|
14
|
+
puts "\nHow many viewings? ('quit' to exit)"
|
15
|
+
answer = gets.chomp.downcase
|
16
|
+
case answer
|
17
|
+
when /^\d+$/
|
18
|
+
playlist1.play(answer.to_i)
|
19
|
+
when 'quit', 'exit'
|
20
|
+
playlist1.print_stats
|
21
|
+
break
|
22
|
+
else
|
23
|
+
puts "Please enter a number or 'quit'"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
playlist1.save
|
28
|
+
# puts "Enjoy your #{answer} viewings..."
|
29
|
+
# playlist1.play(answer.to_i)
|
30
|
+
|
31
|
+
#playlist1.print_stats
|
32
|
+
|
33
|
+
# playlist2 = Playlist.new("Fozzie")
|
34
|
+
# playlist2.add_movie(movie3)
|
35
|
+
|
36
|
+
# movie4 = Movie.new("gemlins", 15)
|
37
|
+
# playlist2.add_movie(movie4)
|
38
|
+
# playlist2.play(3)
|
39
|
+
# playlist2.print_stats
|
40
|
+
|
data/bin/movies.csv
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Rankable
|
2
|
+
def thumbs_up
|
3
|
+
self.rank += 1
|
4
|
+
end
|
5
|
+
|
6
|
+
def thumbs_down
|
7
|
+
self.rank -= 1
|
8
|
+
end
|
9
|
+
|
10
|
+
def hit?
|
11
|
+
self.rank >= 10
|
12
|
+
end
|
13
|
+
|
14
|
+
def status
|
15
|
+
hit? ? "Hit" : "Flop"
|
16
|
+
end
|
17
|
+
|
18
|
+
def normalized_rank
|
19
|
+
self.rank / 10
|
20
|
+
end
|
21
|
+
|
22
|
+
def <=>(other)
|
23
|
+
other.rank <=> self.rank
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/lib/flicks/files.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'movie'
|
2
|
+
|
3
|
+
movie1 = Movie.new("goonies", 10)
|
4
|
+
movie2 = Movie.new("ghostbusters", 9)
|
5
|
+
movie3 = Movie.new("goldfinger")
|
6
|
+
|
7
|
+
movies = [movie1, movie2, movie3]
|
8
|
+
|
9
|
+
File.open("movie_rankings.csv", "w") do |file|
|
10
|
+
movies.sort.each do |movie|
|
11
|
+
file.puts "#{movie.title},#{movie.rank}"
|
12
|
+
end
|
13
|
+
end
|
data/lib/flicks/movie.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require_relative 'rankable'
|
2
|
+
|
3
|
+
module Flicks
|
4
|
+
class Movie
|
5
|
+
include Rankable
|
6
|
+
|
7
|
+
attr_accessor :rank
|
8
|
+
attr_accessor :title
|
9
|
+
|
10
|
+
def initialize(title, rank=0)
|
11
|
+
@title = title.capitalize
|
12
|
+
@rank = rank
|
13
|
+
@snack_carbs = Hash.new(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_csv
|
17
|
+
"#{@title},#{@rank}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_csv(line)
|
21
|
+
title, rank = line.split(',')
|
22
|
+
movie = Movie.new(title, Integer(rank))
|
23
|
+
end
|
24
|
+
|
25
|
+
def each_snack
|
26
|
+
@snack_carbs.each do |name, carbs|
|
27
|
+
snack = Snack.new(name, carbs)
|
28
|
+
yield snack
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def ate_snack(snack)
|
33
|
+
@snack_carbs[snack.name] += snack.carbs
|
34
|
+
puts "#{title} led to #{snack.carbs} #{snack.name}"
|
35
|
+
puts "#{@title}'s snacks: #{@snack_carbs}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def carbs_consumed
|
39
|
+
@snack_carbs.values.reduce(0, :+)
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
"#{@title} has a rank of #{@rank} (#{status})"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
if __FILE__ == $0
|
48
|
+
movie = Movie.new("goonies", 10)
|
49
|
+
puts movie.title
|
50
|
+
puts movie.rank
|
51
|
+
|
52
|
+
movie.thumbs_up
|
53
|
+
movie.thumbs_up
|
54
|
+
puts movie.rank
|
55
|
+
|
56
|
+
movie.thumbs_down
|
57
|
+
puts movie.rank
|
58
|
+
puts movie
|
59
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'movie'
|
2
|
+
module Flicks
|
3
|
+
class Movie3D < Movie
|
4
|
+
def initialize(title, rank, wow_factor)
|
5
|
+
super(title, rank)
|
6
|
+
@wow_factor = wow_factor
|
7
|
+
end
|
8
|
+
|
9
|
+
def thumbs_up
|
10
|
+
@wow_factor.times {super}
|
11
|
+
end
|
12
|
+
|
13
|
+
def show_effect
|
14
|
+
puts "Wow! " * @wow_factor
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
if __FILE__ == $0
|
19
|
+
movie3d = Movie3D.new('glee', 5, 20)
|
20
|
+
puts movie3d.title
|
21
|
+
puts movie3d.rank
|
22
|
+
movie3d.thumbs_up
|
23
|
+
puts movie3d.rank
|
24
|
+
puts movie3d
|
25
|
+
movie3d.show_effect
|
26
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative 'movie'
|
2
|
+
require_relative 'waldorf_and_statler'
|
3
|
+
require_relative 'snack_bar'
|
4
|
+
|
5
|
+
module Flicks
|
6
|
+
class Playlist
|
7
|
+
def initialize(name)
|
8
|
+
@name = name
|
9
|
+
@movies = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def load(from_file)
|
13
|
+
File.readlines(from_file).each do |line|
|
14
|
+
add_movie(Movie.from_csv(line))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def save(to_file = "movie_rankings.csv")
|
19
|
+
File.open(to_file, "w") do |file|
|
20
|
+
@movies.sort.each do |movie|
|
21
|
+
file.puts movie.to_csv
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_movie(movie)
|
27
|
+
@movies << movie
|
28
|
+
end
|
29
|
+
|
30
|
+
def play(viewings)
|
31
|
+
puts "#{@name}'s playlist:"
|
32
|
+
puts @movies.sort
|
33
|
+
|
34
|
+
snacks = SnackBar::SNACKS
|
35
|
+
puts "\nThere are #{snacks.size} snacks available in the snack bar."
|
36
|
+
|
37
|
+
snacks.each do |snack|
|
38
|
+
puts "#{snack.name} has #{snack.carbs} carbs"
|
39
|
+
end
|
40
|
+
|
41
|
+
1.upto(viewings) do |count|
|
42
|
+
puts "\nViewings #{count}:"
|
43
|
+
@movies.each do |movie|
|
44
|
+
WaldorfAndStatler.review(movie)
|
45
|
+
snack = SnackBar.random
|
46
|
+
movie.ate_snack(snack)
|
47
|
+
puts movie
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def total_carbs_consumed
|
53
|
+
@movies.reduce(0) do |sum, movie|
|
54
|
+
sum + movie.carbs_consumed
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def print_stats
|
59
|
+
puts "\n#{@name}'s Stats:"
|
60
|
+
puts "#{total_carbs_consumed} total carbs consumed"
|
61
|
+
@movies.sort.each do |movie|
|
62
|
+
puts "\n#{movie.title}'s snack totals:"
|
63
|
+
movie.each_snack do |snack|
|
64
|
+
puts "#{snack.carbs} total #{snack.name} carbs"
|
65
|
+
end
|
66
|
+
puts "#{movie.carbs_consumed} grand total carbs"
|
67
|
+
end
|
68
|
+
hits, flops = @movies.partition { |movie| movie.hit?}
|
69
|
+
|
70
|
+
puts "\nHits:"
|
71
|
+
puts hits.sort
|
72
|
+
|
73
|
+
puts "\nFlops:"
|
74
|
+
puts flops.sort
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
Snack = Struct.new(:name, :carbs)
|
3
|
+
|
4
|
+
module SnackBar
|
5
|
+
SNACKS = [
|
6
|
+
Snack.new(:popcorn, 20),
|
7
|
+
Snack.new(:candy, 15),
|
8
|
+
Snack.new(:nachos, 40),
|
9
|
+
Snack.new(:pretzel, 10),
|
10
|
+
Snack.new(:soda, 5)
|
11
|
+
]
|
12
|
+
|
13
|
+
def self.random
|
14
|
+
SNACKS.sample
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if __FILE__ == $0
|
19
|
+
puts SnackBar::SNACKS
|
20
|
+
snack = SnackBar.random
|
21
|
+
puts "Enjor your #{snack.name} (#{snack.carbs}) carbs"
|
22
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module WaldorfAndStatler
|
2
|
+
def self.roll_die
|
3
|
+
rand(1..6)
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.review(movie)
|
7
|
+
number_rolled = roll_die
|
8
|
+
case number_rolled
|
9
|
+
when 1..2
|
10
|
+
movie.thumbs_down
|
11
|
+
puts "#{movie.title} got a thumbs down."
|
12
|
+
when 3..4
|
13
|
+
puts "#{movie.title} was skipped."
|
14
|
+
else
|
15
|
+
movie.thumbs_up
|
16
|
+
puts "#{movie.title} got a thumbs up!"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'flicks/movie'
|
2
|
+
module Flicks
|
3
|
+
|
4
|
+
describe Movie do
|
5
|
+
before do
|
6
|
+
@initial_rank = 10
|
7
|
+
@movie = Movie.new("goonies", @initial_rank)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a capitalized title" do
|
11
|
+
@movie.title.should == "Goonies"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a inital rank" do
|
15
|
+
@movie.rank.should == 10
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has a string representation" do
|
19
|
+
@movie.to_s.should == "Goonies has a rank of 10 (Hit)"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "increases rank by 1 when given a thumbs up" do
|
23
|
+
@movie.thumbs_up
|
24
|
+
@movie.rank.should == @initial_rank + 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it "decreases rank by 1 when given a thumbs down" do
|
28
|
+
@movie.thumbs_down
|
29
|
+
@movie.rank.should == @initial_rank - 1
|
30
|
+
end
|
31
|
+
|
32
|
+
context "created with a default rank" do
|
33
|
+
before do
|
34
|
+
@movie = Movie.new("goonies")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a rank of 0" do
|
38
|
+
@movie.rank.should == 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with a rank of at least 10" do
|
43
|
+
before do
|
44
|
+
@movie = Movie.new("goonies", 10)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "is a hit" do
|
48
|
+
@movie.should be_hit
|
49
|
+
end
|
50
|
+
|
51
|
+
it "has a hit status" do
|
52
|
+
@movie.status.should == "Hit"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "with rank of less than 10" do
|
57
|
+
before do
|
58
|
+
@movie = Movie.new("goonies", 9)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "is not a hit" do
|
62
|
+
@movie.should_not be_hit
|
63
|
+
end
|
64
|
+
|
65
|
+
it "has a flop status" do
|
66
|
+
@movie.status.should == "Flop"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "flicks/playlist"
|
2
|
+
|
3
|
+
module Flicks
|
4
|
+
describe Playlist do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@playlist = Playlist.new("Kermit")
|
8
|
+
end
|
9
|
+
|
10
|
+
context "being played with one movie" do
|
11
|
+
before do
|
12
|
+
@initial_rank = 10
|
13
|
+
@movie = Movie.new("goonies", @initial_rank)
|
14
|
+
@playlist.add_movie(@movie)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "gives the movie a thumbs up if a high number is rolled" do
|
18
|
+
WaldorfAndStatler.stub(:roll_die).and_return(5)
|
19
|
+
@playlist.play(1)
|
20
|
+
@movie.rank.should == @initial_rank + 1
|
21
|
+
end
|
22
|
+
|
23
|
+
it "skips the movie if a medium number is rolled" do
|
24
|
+
WaldorfAndStatler.stub(:roll_die).and_return(3)
|
25
|
+
@playlist.play(1)
|
26
|
+
@movie.rank.should == @initial_rank
|
27
|
+
end
|
28
|
+
|
29
|
+
it "gives the movie a thumbs down if a low number is rolled" do
|
30
|
+
WaldorfAndStatler.stub(:roll_die).and_return(1)
|
31
|
+
@playlist.play(1)
|
32
|
+
@movie.rank.should == @initial_rank - 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rwflicks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rusty Walters
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: movie gem created from PragmaticStudio.com ruby training
|
28
|
+
email: rusty.walters@gmail.com
|
29
|
+
executables:
|
30
|
+
- flicks
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/flicks
|
35
|
+
- bin/flicks.rb
|
36
|
+
- bin/movie_rankings.csv
|
37
|
+
- bin/movies.csv
|
38
|
+
- bin/super_hero_movies.csv
|
39
|
+
- lib/flicks/Rankable.rb
|
40
|
+
- lib/flicks/files.rb
|
41
|
+
- lib/flicks/movie.rb
|
42
|
+
- lib/flicks/movie3d.rb
|
43
|
+
- lib/flicks/playlist.rb
|
44
|
+
- lib/flicks/snack_bar.rb
|
45
|
+
- lib/flicks/waldorf_and_statler.rb
|
46
|
+
- spec/flicks/movie_spec.rb
|
47
|
+
- spec/flicks/playlist_spec.rb
|
48
|
+
homepage: http://pragmaticstudio.com
|
49
|
+
licenses: []
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.9'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
requirements: []
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 2.2.2
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: Plays and reviews movies
|
71
|
+
test_files:
|
72
|
+
- spec/flicks/movie_spec.rb
|
73
|
+
- spec/flicks/playlist_spec.rb
|
74
|
+
has_rdoc:
|