flicks 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/flicks +3 -2
- data/lib/flicks/movie.rb +19 -9
- data/lib/flicks/movie3d.rb +15 -5
- data/lib/flicks/playlist.rb +9 -9
- data/lib/flicks/rankable.rb +4 -4
- data/lib/flicks/snack_bar.rb +7 -2
- data/lib/flicks/waldorf_and_statler.rb +1 -3
- data/spec/flicks/snack_bar_spec.rb +2 -3
- metadata +4 -4
data/bin/flicks
CHANGED
@@ -3,8 +3,9 @@
|
|
3
3
|
require_relative '../lib/flicks/playlist'
|
4
4
|
|
5
5
|
playlist = Flicks::Playlist.new("Kermit")
|
6
|
-
|
7
|
-
|
6
|
+
default_movie_file =
|
7
|
+
File.join(File.dirname(__FILE__), 'movies.csv')
|
8
|
+
playlist.load(ARGV.shift || default_movie_file)
|
8
9
|
|
9
10
|
loop do
|
10
11
|
puts "\nHow many viewings? ('quit' to exit)"
|
data/lib/flicks/movie.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative 'rankable'
|
|
4
4
|
module Flicks
|
5
5
|
class Movie
|
6
6
|
include Rankable
|
7
|
-
|
7
|
+
|
8
8
|
attr_accessor :title, :rank
|
9
9
|
|
10
10
|
def initialize(title, rank=0)
|
@@ -12,33 +12,43 @@ module Flicks
|
|
12
12
|
@rank = rank
|
13
13
|
@snack_carbs = Hash.new(0)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def ate_snack(snack)
|
17
17
|
@snack_carbs[snack.name] += snack.carbs
|
18
18
|
puts "#{@title} led to #{snack.carbs} #{snack.name} carbs being consumed."
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def carbs_consumed
|
22
22
|
@snack_carbs.values.reduce(0, :+)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def each_snack
|
26
26
|
@snack_carbs.each do |name, carbs|
|
27
|
-
yield Snack.new(name,
|
27
|
+
yield Snack.new(name, carbs)
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def to_s
|
32
32
|
"#{@title} has a rank of #{@rank} (#{status})"
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def to_csv
|
36
36
|
"#{@title},#{@rank}"
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
def self.from_csv(string)
|
40
40
|
title, rank = string.split(',')
|
41
41
|
new(title, Integer(rank))
|
42
42
|
end
|
43
43
|
end
|
44
|
-
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if __FILE__ == $0
|
47
|
+
movie = Flicks::Movie.new("goonies", 10)
|
48
|
+
puts movie.title
|
49
|
+
puts movie.rank
|
50
|
+
movie.thumbs_up
|
51
|
+
puts movie.rank
|
52
|
+
movie.thumbs_down
|
53
|
+
puts movie.rank
|
54
|
+
end
|
data/lib/flicks/movie3d.rb
CHANGED
@@ -3,18 +3,28 @@ require_relative 'movie'
|
|
3
3
|
module Flicks
|
4
4
|
class Movie3D < Movie
|
5
5
|
attr_reader :wow_factor
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(name, rank, wow_factor)
|
8
8
|
super(name, rank)
|
9
9
|
@wow_factor = wow_factor
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def thumbs_up
|
13
13
|
@wow_factor.times { super }
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def show_effect
|
17
17
|
puts "Wow! " * @wow_factor
|
18
|
-
end
|
18
|
+
end
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if __FILE__ == $0
|
23
|
+
movie3d = Flicks::Movie3D.new('Glee', 5, 10)
|
24
|
+
movie3d.thumbs_up
|
25
|
+
puts movie3d.rank
|
26
|
+
movie3d.thumbs_down
|
27
|
+
puts movie3d.rank
|
28
|
+
puts movie3d
|
29
|
+
movie3d.show_effect
|
30
|
+
end
|
data/lib/flicks/playlist.rb
CHANGED
@@ -6,12 +6,12 @@ require_relative 'snack_bar'
|
|
6
6
|
module Flicks
|
7
7
|
class Playlist
|
8
8
|
attr_reader :name
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(name)
|
11
11
|
@name = name
|
12
12
|
@movies = []
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def add_movie(a_movie)
|
16
16
|
@movies << a_movie
|
17
17
|
end
|
@@ -26,7 +26,7 @@ module Flicks
|
|
26
26
|
snacks.each do |snack|
|
27
27
|
puts "#{snack.name} has #{snack.carbs} carbs"
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
1.upto(viewings) do |count|
|
31
31
|
puts "\nViewing #{count}:"
|
32
32
|
@movies.each do |movie|
|
@@ -37,22 +37,22 @@ module Flicks
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def total_carbs_consumed
|
42
42
|
@movies.reduce(0) { |sum, movie| sum + movie.carbs_consumed }
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def print_stats
|
46
46
|
puts "\n#{@name}'s Stats:"
|
47
47
|
|
48
48
|
hits, flops = @movies.partition {|movie| movie.hit? }
|
49
|
-
|
49
|
+
|
50
50
|
puts "\nHits:"
|
51
51
|
puts hits.sort
|
52
52
|
|
53
53
|
puts "\nFlops:"
|
54
54
|
puts flops.sort
|
55
|
-
|
55
|
+
|
56
56
|
puts "\n#{total_carbs_consumed} total carbs consumed"
|
57
57
|
@movies.sort.each do |movie|
|
58
58
|
puts "\n#{movie.title}'s snack totals:"
|
@@ -62,13 +62,13 @@ module Flicks
|
|
62
62
|
puts "#{movie.carbs_consumed} grand total carbs"
|
63
63
|
end
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def load(from_file)
|
67
67
|
File.readlines(from_file).each do |line|
|
68
68
|
add_movie(Movie.from_csv(line))
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
def save(to_file="movie_rankings.csv")
|
73
73
|
File.open(to_file, "w") do |file|
|
74
74
|
file.puts @movies.sort.map { |movie| movie.to_csv }
|
data/lib/flicks/rankable.rb
CHANGED
@@ -3,19 +3,19 @@ module Flicks
|
|
3
3
|
def thumbs_up
|
4
4
|
self.rank += 1
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
7
|
def thumbs_down
|
8
8
|
self.rank -= 1
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def hit?
|
12
12
|
self.rank >= 10
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def status
|
16
16
|
hit? ? "Hit": "Flop"
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def <=>(other)
|
20
20
|
other.rank <=> self.rank
|
21
21
|
end
|
data/lib/flicks/snack_bar.rb
CHANGED
@@ -15,10 +15,9 @@ module Flicks
|
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
18
|
-
end
|
19
18
|
|
20
|
-
module Flicks
|
21
19
|
describe SnackBar do
|
20
|
+
|
22
21
|
it "has a trove of treasures" do
|
23
22
|
SnackBar::SNACKS.should_not be_empty
|
24
23
|
end
|
@@ -29,4 +28,4 @@ module Flicks
|
|
29
28
|
SnackBar::SNACKS.should include(snack)
|
30
29
|
end
|
31
30
|
end
|
32
|
-
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flicks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70102011883120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70102011883120
|
25
25
|
description: ! "This is an example application used in The Pragmatic Studio's \nRuby
|
26
26
|
Programming course, as described at\n\n http://pragmaticstudio.com\n\nThis code
|
27
27
|
is Copyright 2012 The Pragmatic Studio. See the LICENSE file."
|