flicks-example 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 33fc1838aacfa8b8979511c456d302322e4f87dbf546f33614ef1362c0a18c73
4
+ data.tar.gz: 6787741d7d77965a60f32e2a50a87020c94b71243e9fa278ae87b0a2da9f947b
5
+ SHA512:
6
+ metadata.gz: f24ecb9b090ad9fa805e5028f9dd78282f22ecab14861148594e2afe565731cde0939ed0d79d372da663cf00bc0850aefd76586615ae22936753b6c39a55101d
7
+ data.tar.gz: c0b5dfb316224d8dc94b3f854ba1d0760261a31694928895e6a6d232dfb61732121d60c075fbd6d5349342e20bcfec252668a93688062b09e8cd0b35782f1bcb
data/LICENSE ADDED
File without changes
data/README ADDED
File without changes
data/bin/flicks ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/flicks/playlist'
3
+ require_relative '../lib/flicks/movie3d'
4
+
5
+ playlist = Flicks::Playlist.new("Kermit")
6
+ default_movie_file = File.join(File.dirname(__FILE__), "movies.csv")
7
+ playlist.load(ARGV.shift || default_movie_file)
8
+ movie3d = Flicks::Movie3D.new('glee', 5, 10)
9
+ playlist.add_movie(movie3d)
10
+
11
+ loop do
12
+ puts "\nHow many viewings? ('quit' to exit)"
13
+ answer = gets.chomp.downcase
14
+
15
+ case answer
16
+ when /^\d+$/
17
+ playlist.play(answer.to_i)
18
+ when 'quit', 'exit'
19
+ playlist.print_stats
20
+ break
21
+ else
22
+ puts "Please enter a number or 'quit'"
23
+ end
24
+ end
25
+
26
+ playlist.save
data/bin/movies.csv ADDED
@@ -0,0 +1,3 @@
1
+ Goonies,10
2
+ Ghostbusters,9
3
+ Goldfinger,0
@@ -0,0 +1,60 @@
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 self.from_csv(line)
17
+ title, rank = line.split(",")
18
+ Movie.new(title, Integer(rank))
19
+ end
20
+
21
+ def to_csv
22
+ "#{@title},#{@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 carbs_consumed
33
+ @snack_carbs.values.reduce(0, :+)
34
+ end
35
+
36
+ def ate_snack(snack)
37
+ @snack_carbs[snack.name] += snack.carbs
38
+ puts "#{@title} led to #{snack.carbs} #{snack.name} carbs being consumed."
39
+ puts "#{@title}'s snacks: #{@snack_carbs}"
40
+ end
41
+
42
+ def to_s
43
+ "#{@title} has a rank of #{@rank} (#{status})"
44
+ end
45
+ end
46
+ end
47
+
48
+ if __FILE__ == $0
49
+ movie = Flicks::Movie.new("goonies", 10)
50
+ puts movie.title
51
+ puts movie.rank
52
+
53
+ movie.thumbs_up
54
+ movie.thumbs_up
55
+ puts movie.rank
56
+
57
+ movie.thumbs_down
58
+ puts movie.rank
59
+ puts movie
60
+ end
@@ -0,0 +1,31 @@
1
+ require_relative 'movie'
2
+
3
+ module Flicks
4
+ class Movie3D < Movie
5
+ def initialize(title, rank, wow_factor)
6
+ super(title, rank)
7
+ @wow_factor = wow_factor
8
+ end
9
+
10
+ def thumbs_up
11
+ @wow_factor.times { super }
12
+ end
13
+
14
+ def wow_effect
15
+ puts "Wow! " * @wow_factor
16
+ end
17
+ end
18
+ end
19
+
20
+ if __FILE__ == $0
21
+ movie3d = Flicks::Movie3D.new('glee', 5, 20)
22
+ puts movie3d.title
23
+ puts movie3d.rank
24
+
25
+ movie3d.thumbs_up
26
+
27
+ puts movie3d.rank
28
+ puts movie3d
29
+
30
+ puts movie3d.wow_effect
31
+ end
@@ -0,0 +1,80 @@
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
+
33
+ puts @movies.sort
34
+
35
+ snacks = SnackBar::SNACKS
36
+ puts "\nThere are #{snacks.size} snacks available in the snack bar."
37
+
38
+ snacks.each do |snack|
39
+ puts "#{snack.name} has #{snack.carbs} carbs"
40
+ end
41
+
42
+ 1.upto(viewings) do |count|
43
+ puts "\nViewing #{count}:"
44
+ @movies.each do |movie|
45
+ WaldorfAndStatler.review(movie)
46
+ snack = SnackBar.random
47
+ movie.ate_snack(snack)
48
+ puts movie
49
+ end
50
+ end
51
+ end
52
+
53
+ def total_carbs_consumed
54
+ @movies.reduce(0) do |sum, movie|
55
+ sum + movie.carbs_consumed
56
+ end
57
+ end
58
+
59
+ def print_stats
60
+ puts "\n#{@name}'s Stats:"
61
+
62
+ puts "#{total_carbs_consumed} total carbs consumed"
63
+ @movies.sort.each do |movie|
64
+ puts "\n#{movie.title}'s snack totals:"
65
+ movie.each_snack do |snack|
66
+ puts "#{snack.name} total #{snack.carbs} carbs"
67
+ end
68
+ puts "#{movie.carbs_consumed} grand total carbs"
69
+ end
70
+
71
+ hits, flops = @movies.partition { |movie| movie.hit? }
72
+
73
+ puts "\nHits:"
74
+ puts hits.sort
75
+
76
+ puts "\nFlops:"
77
+ puts flops.sort
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,23 @@
1
+ module Flicks
2
+ module Rankable
3
+ def thumbs_up
4
+ self.rank += 1
5
+ end
6
+
7
+ def thumbs_down
8
+ self.rank -= 1
9
+ end
10
+
11
+ def hit?
12
+ self.rank >= 10
13
+ end
14
+
15
+ def status
16
+ hit? ? "Hit" : "Flop"
17
+ end
18
+
19
+ def <=>(other)
20
+ other.rank <=> self.rank
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ Snack = Struct.new(:name, :carbs)
2
+
3
+ module SnackBar
4
+ SNACKS = [
5
+ Snack.new(:popcorn, 20),
6
+ Snack.new(:candy, 15),
7
+ Snack.new(:nachos, 40),
8
+ Snack.new(:pretzel, 10),
9
+ Snack.new(:soda, 5),
10
+ ]
11
+
12
+ def self.random
13
+ SNACKS.sample
14
+ end
15
+ end
16
+
17
+ if __FILE__ == $0
18
+ puts SnackBar::SNACKS
19
+ snack = SnackBar.random
20
+ puts "Enjoy your #{snack.name} (#{snack.carbs} carbs)"
21
+ end
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,70 @@
1
+ require 'flicks/movie'
2
+
3
+ module Flicks
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 capitalize title" do
11
+ expect(@movie.title).to eq "Goonies"
12
+ end
13
+
14
+ it "has an initial rank" do
15
+ expect(@movie.rank).to eq 10
16
+ end
17
+
18
+ it "has a string representation" do
19
+ expect(@movie.to_s).to eq "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
+ expect(@movie.rank).to eq @initial_rank + 1
25
+ end
26
+
27
+ it "decreases rank by 1 when given a thumbs down" do
28
+ @movie.thumbs_down
29
+ expect(@movie.rank).to eq @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
+ expect(@movie.rank).to eq 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
+ expect(@movie).to be_hit
49
+ end
50
+
51
+ it "has a hit status" do
52
+ expect(@movie.status).to eq "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
+ expect(@movie).not_to be_hit
63
+ end
64
+
65
+ it "has a flop status" do
66
+ expect(@movie.status).to eq "Flop"
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,35 @@
1
+ require 'flicks/playlist'
2
+
3
+ module Flicks
4
+ describe Playlist do
5
+ before do
6
+ @playlist = Playlist.new("Kermit")
7
+ end
8
+
9
+ context "being played with one movie" do
10
+ before do
11
+ @initial_rank = 10
12
+ @movie = Movie.new("goonies", @initial_rank)
13
+ @playlist.add_movie(@movie)
14
+ end
15
+
16
+ it "gives the movie a thumbs up if a high number is rolled" do
17
+ allow(WaldorfAndStatler).to receive(:roll_die).and_return(5)
18
+ @playlist.play 1
19
+ expect(@movie.rank).to be @initial_rank + 1
20
+ end
21
+
22
+ it "skips the movie if a medium number is rolled" do
23
+ allow(WaldorfAndStatler).to receive(:roll_die).and_return(3)
24
+ @playlist.play 1
25
+ expect(@movie.rank).to be @initial_rank
26
+ end
27
+
28
+ it "gives the movie a thumbs down if a low number is rolled" do
29
+ allow(WaldorfAndStatler).to receive(:roll_die).and_return(1)
30
+ @playlist.play 1
31
+ expect(@movie.rank).to be @initial_rank - 1
32
+ end
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flicks-example
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Echeverri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-01-07 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: '3.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.13'
27
+ description: ''
28
+ email: email@example.com
29
+ executables:
30
+ - flicks
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README
36
+ - bin/flicks
37
+ - bin/movies.csv
38
+ - lib/flicks/movie.rb
39
+ - lib/flicks/movie3d.rb
40
+ - lib/flicks/playlist.rb
41
+ - lib/flicks/rankable.rb
42
+ - lib/flicks/snack_bar.rb
43
+ - lib/flicks/waldorf_and_statler.rb
44
+ - spec/flicks/movie_spec.rb
45
+ - spec/flicks/playlist_spec.rb
46
+ homepage: http://www.example.com/flicks
47
+ licenses: []
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 3.3.4
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubygems_version: 3.5.11
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Plays and reviews movies
68
+ test_files:
69
+ - spec/flicks/movie_spec.rb
70
+ - spec/flicks/playlist_spec.rb