flicksarcs 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/LICENSE +0 -0
- data/README +0 -0
- data/bin/flicks +35 -0
- data/bin/movies.csv +3 -0
- data/bin/superheroes_movies.csv +3 -0
- data/lib/flicks/files.rb +21 -0
- data/lib/flicks/movie.rb +70 -0
- data/lib/flicks/playlist.rb +77 -0
- data/lib/flicks/snack_bar.rb +24 -0
- data/lib/flicks/waldorf_and_statler.rb +18 -0
- data/spec/flicks/movie_spec.rb +68 -0
- data/spec/flicks/playlist_spec.rb +33 -0
- metadata +73 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 5cb40e482b83cb40073a61af8974a9ec15cd8ae34b87be9d4aab518047f4c575
|
|
4
|
+
data.tar.gz: 77f27ba45681de396329f9b7d61410e0af06fa7ed17b514a9a3fd362db2c11e2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2e2943d4f79ccd83b71d71b143a6a13f5cdb3e2d2d0c11219731a82d02a9ef8633a2e3b6a03e06272344c012bd747bbc87bab13db33e6ec732d493a59c220177
|
|
7
|
+
data.tar.gz: a803558470b1182c7837f2f5394c508547ffc706f1686cce02586805ee78e38302dc7d23dd5aaaa7f189d25e286b8b3f26e484ffd9c2d58e3625c61d206d8b74
|
data/LICENSE
ADDED
|
File without changes
|
data/README
ADDED
|
File without changes
|
data/bin/flicks
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/flicks/movie'
|
|
4
|
+
require_relative '../lib/flicks/playlist'
|
|
5
|
+
|
|
6
|
+
# movie1 = Movie.new('Goonies', 10)
|
|
7
|
+
# movie2 = Movie.new('Ghostbusters', 9)
|
|
8
|
+
# movie3 = Movie.new('Goldfinger')
|
|
9
|
+
|
|
10
|
+
# playlist = Playlist.new('Kermit')
|
|
11
|
+
# playlist.add_movie(movie1)
|
|
12
|
+
# playlist.add_movie(movie2)
|
|
13
|
+
# playlist.add_movie(movie3)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
playlist = Flicks::Playlist.new('The Playlist')
|
|
17
|
+
default_movie_file =
|
|
18
|
+
File.join(File.dirname(__FILE__), "movies.csv")
|
|
19
|
+
playlist.load(ARGV.shift || default_movie_file)
|
|
20
|
+
|
|
21
|
+
loop do
|
|
22
|
+
puts "How many viewings? ('quit' to exit)"
|
|
23
|
+
answer = gets.chomp.downcase
|
|
24
|
+
case answer
|
|
25
|
+
when /^\d+$/
|
|
26
|
+
playlist.play(answer.to_i)
|
|
27
|
+
when 'quit', 'exit'
|
|
28
|
+
playlist.print_stats
|
|
29
|
+
break
|
|
30
|
+
else
|
|
31
|
+
puts "Please enter a number or quit"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
playlist.save
|
data/bin/movies.csv
ADDED
data/lib/flicks/files.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_relative 'movie'
|
|
2
|
+
|
|
3
|
+
# File.readlines("movies.csv").each do |line|
|
|
4
|
+
# title, rank = line.split(",")
|
|
5
|
+
# movie = Movie.new(title, rank.to_i)
|
|
6
|
+
# puts movie
|
|
7
|
+
# end
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
movie1 = Movie.new('Goonies', 10)
|
|
11
|
+
movie2 = Movie.new('Ghostbusters', 9)
|
|
12
|
+
movie3 = Movie.new('Goldfinger')
|
|
13
|
+
|
|
14
|
+
movies = [movie1, movie2, movie3]
|
|
15
|
+
|
|
16
|
+
File.open("movie_rankings.csv", "w") do |file|
|
|
17
|
+
movies.sort.each do |movie|
|
|
18
|
+
file.puts "#{movie.title},#{movie.rank}"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
data/lib/flicks/movie.rb
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
module Flicks
|
|
2
|
+
class Movie
|
|
3
|
+
attr_reader :rank
|
|
4
|
+
attr_accessor :title
|
|
5
|
+
|
|
6
|
+
def initialize(title, rank = 0)
|
|
7
|
+
@title = title.capitalize
|
|
8
|
+
@rank = rank
|
|
9
|
+
@snack_carbs = Hash.new(0)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def each_snack
|
|
13
|
+
@snack_carbs.each do |name, carbs|
|
|
14
|
+
snack = Snack.new(name, carbs)
|
|
15
|
+
yield snack
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def carbs_consumed
|
|
20
|
+
@snack_carbs.values.reduce(0, :+)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def ate_snack(snack)
|
|
24
|
+
@snack_carbs[snack.name] += snack.carbs
|
|
25
|
+
puts "#{@title} led to #{snack.carbs} #{snack.name} carbs being consumed"
|
|
26
|
+
puts "#{@title}'s snacks: #{@snack_carbs}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def normalized_rank
|
|
30
|
+
@rank / 10
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def thumbs_up
|
|
34
|
+
@rank += 1
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def thumbs_down
|
|
38
|
+
@rank -= 1
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def hit?
|
|
42
|
+
@rank >= 10
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def status
|
|
46
|
+
hit? ? 'Hit' : 'Flop'
|
|
47
|
+
# if self.hit?
|
|
48
|
+
# "Hit"
|
|
49
|
+
# else
|
|
50
|
+
# "Flop"
|
|
51
|
+
# end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def <=>(other_movie)
|
|
55
|
+
other_movie.rank <=> @rank
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def to_s
|
|
59
|
+
"#{@title} has a rank of #{@rank} (#{status})"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
if $PROGRAM_NAME == __FILE__
|
|
65
|
+
movie = Movies::Movie.new('Goonies', 10)
|
|
66
|
+
puts movie
|
|
67
|
+
puts 'Give movie a thumbs up..'
|
|
68
|
+
movie.thumbs_up
|
|
69
|
+
puts movie
|
|
70
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
title, rank = line.split(',')
|
|
15
|
+
movie = Flicks::Movie.new(title, rank.to_i)
|
|
16
|
+
add_movie(movie)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def save(to_file = 'movie_rankings.csv')
|
|
21
|
+
File.open(to_file, 'w') do |file|
|
|
22
|
+
@movies.sort.each do |movie|
|
|
23
|
+
file.puts "#{movie.title},#{movie.rank}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def add_movie(movie)
|
|
29
|
+
@movies << movie
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def play(viewings)
|
|
33
|
+
puts "#{@name}'s playlist:'"
|
|
34
|
+
puts @movies.sort
|
|
35
|
+
|
|
36
|
+
snacks = SnackBar::SNACKS
|
|
37
|
+
puts "\There are #{snacks.size} snacks available in the snack bar."
|
|
38
|
+
|
|
39
|
+
snacks.each do |snack|
|
|
40
|
+
puts "#{snack.name} has #{snack.carbs} carbs"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
1.upto(viewings) do |count|
|
|
44
|
+
puts "\nViewing: #{count}"
|
|
45
|
+
@movies.each do |movie|
|
|
46
|
+
WaldorfAndStatler.review(movie)
|
|
47
|
+
snack = SnackBar.random
|
|
48
|
+
movie.ate_snack(snack)
|
|
49
|
+
puts movie
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def total_carbs_consumed
|
|
55
|
+
@movies.reduce(0) do |sum, movie|
|
|
56
|
+
sum + movie.carbs_consumed
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def print_stats
|
|
61
|
+
puts "\n#{@name}'s Stats:"
|
|
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.carbs} total #{snack.name} carbs"
|
|
67
|
+
end
|
|
68
|
+
puts "#{movie.carbs_consumed} grand total carbs"
|
|
69
|
+
end
|
|
70
|
+
hits, flops = @movies.partition(&:hit?)
|
|
71
|
+
puts "\nHits:"
|
|
72
|
+
puts hits.sort
|
|
73
|
+
puts "\nFlops:"
|
|
74
|
+
puts flops.sort
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
Snack = Struct.new(:name, :carbs)
|
|
2
|
+
|
|
3
|
+
module SnackBar
|
|
4
|
+
SNACKS = [
|
|
5
|
+
popcorn = Snack.new(:popcorn, 20),
|
|
6
|
+
candy = Snack.new(:candy, 15),
|
|
7
|
+
nachos = Snack.new(:nachos, 40),
|
|
8
|
+
pretzel = Snack.new(:pretzel, 10),
|
|
9
|
+
soda = Snack.new(:soda, 5)
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
def self.random
|
|
13
|
+
SNACKS.sample
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if __FILE__ == $0
|
|
20
|
+
puts SnackBar::SNACKS
|
|
21
|
+
snack = SnackBar.random
|
|
22
|
+
puts "\nEnjoy your #{snack.name} (#{snack.carbs} carbs)"
|
|
23
|
+
end
|
|
24
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module WaldorfAndStatler
|
|
2
|
+
|
|
3
|
+
def self.roll_die
|
|
4
|
+
rand(1..6)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def self.review(movie)
|
|
8
|
+
number_rolled = roll_die
|
|
9
|
+
case number_rolled
|
|
10
|
+
when 1..2
|
|
11
|
+
movie.thumbs_down
|
|
12
|
+
when 3..4
|
|
13
|
+
puts "#{movie.title} was skipped"
|
|
14
|
+
else
|
|
15
|
+
movie.thumbs_up
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
require 'flicks/movie'
|
|
2
|
+
|
|
3
|
+
describe Flicks::Movie do
|
|
4
|
+
before do
|
|
5
|
+
@initial_rank = 10
|
|
6
|
+
@movie = Flicks::Movie.new('goonies', @initial_rank)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'has a capitalized title' do
|
|
10
|
+
expect(@movie.title).to eq 'Goonies'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'has an initial rank' do
|
|
14
|
+
expect(@movie.rank).to eq 10
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'has a string representation' do
|
|
18
|
+
expect(@movie.to_s).to eq 'Goonies has a rank of 10 (Hit)'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'increases the rank by one when given thumbs up' do
|
|
22
|
+
@movie.thumbs_up
|
|
23
|
+
expect(@movie.rank).to eq (@initial_rank + 1)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'decreases the rank by one when given thumbs down' do
|
|
27
|
+
@movie.thumbs_down
|
|
28
|
+
expect(@movie.rank).to eq (@initial_rank - 1)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context 'created with a default rank' do
|
|
32
|
+
before do
|
|
33
|
+
@movie = Flicks::Movie.new('goonies')
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'has a rank of 0' do
|
|
37
|
+
expect(@movie.rank).to eq 0
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context 'movie with a rank of at least 10' do
|
|
42
|
+
before do
|
|
43
|
+
@movie = Flicks::Movie.new('goonies', 10)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'is a hit' do
|
|
47
|
+
expect(@movie.hit?).to be true
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'has a hit status' do
|
|
51
|
+
expect(@movie.status).to eq "Hit"
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context 'movie with a rank of less than 10' do
|
|
56
|
+
before do
|
|
57
|
+
@movie = Flicks::Movie.new('goonies', 9)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'is not a hit' do
|
|
61
|
+
expect(@movie.hit?).to be false
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'has a flop status' do
|
|
65
|
+
expect(@movie.status).to eq "Flop"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'flicks/playlist'
|
|
2
|
+
|
|
3
|
+
describe Flicks::Playlist do
|
|
4
|
+
before do
|
|
5
|
+
@playlist = Flicks::Playlist.new('Kermit')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context 'being played with one movie' do
|
|
9
|
+
before do
|
|
10
|
+
@initial_rank = 10
|
|
11
|
+
@movie = Flicks::Movie.new('goonies', @initial_rank)
|
|
12
|
+
@playlist.add_movie(@movie)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'gives the movie a thumbs up if a high number is rolled' do
|
|
16
|
+
WaldorfAndStatler.stub(:roll_die).and_return(5)
|
|
17
|
+
@playlist.play(1)
|
|
18
|
+
expect(@movie.rank).to eq @initial_rank + 1
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'skips the movie if a medium number is rolled' do
|
|
22
|
+
WaldorfAndStatler.stub(:roll_die).and_return(3)
|
|
23
|
+
@playlist.play(1)
|
|
24
|
+
expect(@movie.rank).to eq @initial_rank
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'gives the movie a thumbs down if a low number is rolled' do
|
|
28
|
+
WaldorfAndStatler.stub(:roll_die).and_return(1)
|
|
29
|
+
@playlist.play(1)
|
|
30
|
+
expect(@movie.rank).to eq @initial_rank - 1
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: flicksarcs
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Richard Seldon
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-07-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: '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: Simple POC movie app
|
|
28
|
+
email: arcseldon@gmail.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
|
+
- bin/superheroes_movies.csv
|
|
39
|
+
- lib/flicks/files.rb
|
|
40
|
+
- lib/flicks/movie.rb
|
|
41
|
+
- lib/flicks/playlist.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:
|
|
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: '2.0'
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
requirements: []
|
|
64
|
+
rubyforge_project:
|
|
65
|
+
rubygems_version: 2.7.6
|
|
66
|
+
signing_key:
|
|
67
|
+
specification_version: 4
|
|
68
|
+
summary: Simple demonstration ruby gem
|
|
69
|
+
test_files:
|
|
70
|
+
- spec/flicks/playlist_spec.rb
|
|
71
|
+
- spec/flicks/movie_spec.rb
|
|
72
|
+
- LICENSE
|
|
73
|
+
- README
|