flicks1 1.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 +1 -0
- data/README +1 -0
- data/bin/flicks +40 -0
- data/bin/movies.csv +3 -0
- data/lib/flicks/inheritance.rb +32 -0
- data/lib/flicks/movie.rb +60 -0
- data/lib/flicks/playlist.rb +77 -0
- data/lib/flicks/rankable.rb +31 -0
- data/lib/flicks/snack_bar.rb +25 -0
- data/lib/flicks/waldorf_and_statler.rb +29 -0
- data/spec/flicks/movie_spec.rb +40 -0
- data/spec/flicks/playlist_spec.rb +40 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: caab57cc75852f01b07bd9c6f03603f9973cdca2
|
4
|
+
data.tar.gz: e483fc8d412a34949c2eea638b84018ebc85d5e9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6f890ad424c905517083de45a6634739754b9925962ed80dd6026b6767ff15bf9239075e893bffd32a626ec356861da2a53512f506146c53f74ef35aa9f8be1b
|
7
|
+
data.tar.gz: 3981000d4b15fc4baba4473dbc0c4ba78fcc7906a502923745d80694099666005d697db7ed128626f272d524dcfd8ce016ca157f8975078fab8a2ccafaf1e018
|
data/LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
THIS IS MY LICENSE. :)
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Just practicing making gem
|
data/bin/flicks
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/flicks/playlist'
|
4
|
+
require_relative '../lib/flicks/inheritance'
|
5
|
+
|
6
|
+
|
7
|
+
module Flicks
|
8
|
+
playlist1 = Playlist.new('Kermit')
|
9
|
+
|
10
|
+
default_movie_path = File.join(File.dirname(__FILE__),'movies.csv')
|
11
|
+
puts "Loading default Path since no ARGV is given: #{default_movie_path}"
|
12
|
+
|
13
|
+
playlist1.load(ARGV.shift || default_movie_path )
|
14
|
+
|
15
|
+
playlist1.add_movie(Movie3D.new('Batman vs Superman',7,10))
|
16
|
+
|
17
|
+
counter = 0
|
18
|
+
loop do
|
19
|
+
puts "\nHow many viewings? ('quit' to 'exit')"
|
20
|
+
answer = gets.chomp.downcase
|
21
|
+
case answer
|
22
|
+
when 'quit','exit'
|
23
|
+
puts "Thank you for playing"
|
24
|
+
playlist1.print_stats
|
25
|
+
playlist1.save unless counter == 0
|
26
|
+
break
|
27
|
+
when /^\d+$/ #rubular expression can pick up integers in string format
|
28
|
+
unless answer == "0"
|
29
|
+
puts "Enjoy your #{answer} viewings"
|
30
|
+
counter += 1
|
31
|
+
playlist1.play(answer.to_i)
|
32
|
+
else
|
33
|
+
puts "Can't play if it's 0 viewings.."
|
34
|
+
end
|
35
|
+
else
|
36
|
+
puts "Either enter a number greater than 0 or 'quit' to exit"
|
37
|
+
p answer
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/bin/movies.csv
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'movie'
|
2
|
+
|
3
|
+
module Flicks
|
4
|
+
class Movie3D < Movie
|
5
|
+
attr_accessor :wow_factor
|
6
|
+
|
7
|
+
def initialize(title,rank,wow_factor)
|
8
|
+
super(title,rank)
|
9
|
+
@wow_factor = wow_factor
|
10
|
+
end
|
11
|
+
|
12
|
+
def thumbs_up
|
13
|
+
@wow_factor.times { super }
|
14
|
+
end
|
15
|
+
|
16
|
+
def show_effect
|
17
|
+
puts "Wow" * @wow_factor
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
puts super
|
22
|
+
puts "Also with a wow_factor of #{@wow_factor}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if __FILE__ == $0
|
28
|
+
movie3d = Movie3D.new('something',10,10)
|
29
|
+
puts movie3d
|
30
|
+
puts movie3d.thumbs_up
|
31
|
+
puts movie3d
|
32
|
+
end
|
data/lib/flicks/movie.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative 'rankable'
|
2
|
+
|
3
|
+
module Flicks
|
4
|
+
class Movie
|
5
|
+
include Rankable
|
6
|
+
attr_accessor :title,:rank,:snack_carbs
|
7
|
+
|
8
|
+
def initialize(title,rank=0)
|
9
|
+
@title = title.capitalize
|
10
|
+
@rank = rank
|
11
|
+
@snack_carbs = Hash.new(0)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.convert(line)
|
15
|
+
title,rank = line.split(",")
|
16
|
+
return Movie.new(title,Integer(rank))
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_csv
|
20
|
+
"#{@title},#{@rank}"
|
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 consumed snacks: #{@snack_carbs}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def each_snack
|
30
|
+
@snack_carbs.each do |key,value|
|
31
|
+
snack = Snack.new(key,Integer(value))
|
32
|
+
yield snack
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def carbs_consumed
|
37
|
+
@snack_carbs.values.reduce(0) {|sum,n| sum + n }
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
"#{@title} has a rank of #{@rank} (#{status})"
|
42
|
+
end
|
43
|
+
|
44
|
+
class << self #or object name
|
45
|
+
def whatsgood
|
46
|
+
"Another way to define singleton method"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if __FILE__ == $0
|
53
|
+
# movie = Movie.new('goonies',10)
|
54
|
+
# puts movie.title
|
55
|
+
# puts movie.rank
|
56
|
+
# puts movie.normalized_rank
|
57
|
+
# puts movie.thumbs_up
|
58
|
+
# puts movie.thumbs_down
|
59
|
+
# puts movie
|
60
|
+
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 = Array.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def load(from_file)
|
13
|
+
puts "::Loading #{from_file}::"
|
14
|
+
File.readlines(from_file).each do |line|
|
15
|
+
add_movie(Movie.convert(line))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def Playlist.saving_time
|
20
|
+
Time.new.strftime('Printed on %m/%d/%Y at %I:%M%p')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def save(to_file='final_scores.csv')
|
25
|
+
File.open(to_file,'a+') do |file|
|
26
|
+
@movies.sort {|a,z| z.rank <=> a.rank}.each do |movie|
|
27
|
+
file.puts(movie.to_csv)
|
28
|
+
end
|
29
|
+
file.puts(Playlist.saving_time)
|
30
|
+
end
|
31
|
+
puts "\n::::Total Stats Saved to #{to_file}::::"
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_movie(movie)
|
35
|
+
puts "::Adding #{movie.title} to playlist"
|
36
|
+
@movies.push(movie)
|
37
|
+
end
|
38
|
+
|
39
|
+
def play(viewings)
|
40
|
+
puts "#{@name}'s playlist:"
|
41
|
+
puts @movies.sort
|
42
|
+
|
43
|
+
puts "There are #{SnackBar::SNACKS.size} snacks in the Snack Bar"
|
44
|
+
SnackBar::SNACKS.map.with_index(1) {|snack,i| puts "\t#{i}. #{snack.name} #{snack.carbs} carbs"}
|
45
|
+
|
46
|
+
1.upto(viewings) do |count|
|
47
|
+
@movies.sort.each do |movie|
|
48
|
+
puts "\nViewing #{count}:"
|
49
|
+
WaldorfAndStatler.review(movie)
|
50
|
+
movie.ate_snack(SnackBar.random)
|
51
|
+
puts movie
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def print_stats
|
57
|
+
puts "\n#{@name}'s Stats"
|
58
|
+
|
59
|
+
movies_ordered_by_carbs = @movies.sort {|a,z| z.carbs_consumed <=> a.carbs_consumed}
|
60
|
+
movies_ordered_by_carbs.map.with_index(1) do |movie,i|
|
61
|
+
puts "#{i}. #{movie.title} - #{movie.carbs_consumed} total carbs(#{movie.snack_carbs.keys.size} snacks)"
|
62
|
+
movie.each_snack do |snack|
|
63
|
+
puts "\t#{snack.name.capitalize} - #{snack.carbs} carbs"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
hits, flops = @movies.partition {|movie| movie.hit? }
|
69
|
+
|
70
|
+
puts "\nHits:"
|
71
|
+
puts hits.sort {|a,z| z.rank <=> a.rank }
|
72
|
+
puts "\nFlops:"
|
73
|
+
puts flops.sort {|d,q| q.rank <=> d.rank }
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rankable
|
2
|
+
|
3
|
+
def self.introduction
|
4
|
+
puts "Greetings. This module was first designed for instances of class Movie"
|
5
|
+
end
|
6
|
+
|
7
|
+
def thumbs_up
|
8
|
+
self.rank += 1
|
9
|
+
end
|
10
|
+
|
11
|
+
def thumbs_down
|
12
|
+
self.rank -= 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def hit?
|
16
|
+
self.rank >= 10
|
17
|
+
end
|
18
|
+
|
19
|
+
def status
|
20
|
+
hit? ? "Hit" : "Flop"
|
21
|
+
end
|
22
|
+
|
23
|
+
def normalized_rank
|
24
|
+
self.rank / 10
|
25
|
+
end
|
26
|
+
|
27
|
+
def <=>(object)
|
28
|
+
object.rank <=> self.rank
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Flicks
|
2
|
+
Snack = Struct.new(:name,:carbs)
|
3
|
+
|
4
|
+
module SnackBar
|
5
|
+
|
6
|
+
SNACKS = [
|
7
|
+
Snack.new(:popcorn,20),
|
8
|
+
Snack.new(:candy,15),
|
9
|
+
Snack.new(:nachos,40),
|
10
|
+
Snack.new(:pretzel,20),
|
11
|
+
Snack.new(:soda,5)
|
12
|
+
]
|
13
|
+
|
14
|
+
def self.random
|
15
|
+
SNACKS.sample
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
if __FILE__ == $0
|
22
|
+
puts SnackBar::SNACKS
|
23
|
+
random = SnackBar.random
|
24
|
+
puts "Enjoy your #{random.name} with #{random.carbs} carbs"
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module Flicks
|
3
|
+
module WaldorfAndStatler
|
4
|
+
|
5
|
+
def self.roll_die
|
6
|
+
rand(1..6)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.review(movie)
|
10
|
+
case(roll_die)
|
11
|
+
when(0..2)
|
12
|
+
movie.thumbs_down
|
13
|
+
puts "#{movie.title} got a thumbs down."
|
14
|
+
when(3..4)
|
15
|
+
puts "#{movie.title} was skipped"
|
16
|
+
else
|
17
|
+
movie.thumbs_up
|
18
|
+
puts "#{movie.title} got a thumbs up!"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
if __FILE__ == $0
|
26
|
+
movie = Movie.new('harry potter')
|
27
|
+
WaldorfAndStatler.review(movie)
|
28
|
+
end
|
29
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'flicks/movie'
|
2
|
+
|
3
|
+
module Flicks
|
4
|
+
RSpec.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
|
+
expect(@movie.title).to eq(@movie.title.capitalize)
|
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("#{@movie.title} has a rank of #{@movie.rank} (Hit)")
|
20
|
+
end
|
21
|
+
|
22
|
+
it('increases rank by 1 when given a thumbs up') do
|
23
|
+
expect(@movie.thumbs_up).to eq(@initial_rank + 1)
|
24
|
+
end
|
25
|
+
|
26
|
+
it('decreases rank by 1 when given a thumbs down') do
|
27
|
+
expect(@movie.thumbs_down).to eq(@initial_rank - 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
context("created with default rank") do
|
31
|
+
before do
|
32
|
+
@movie = Movie.new('goonies')
|
33
|
+
end
|
34
|
+
|
35
|
+
it('has default value of 0') do
|
36
|
+
expect(@movie.rank).to eq(0)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'flicks/playlist'
|
2
|
+
require 'flicks/waldorf_and_statler'
|
3
|
+
|
4
|
+
module Flicks
|
5
|
+
RSpec.describe(Playlist) do
|
6
|
+
before do
|
7
|
+
$stdout = StringIO.new
|
8
|
+
@playlist = Playlist.new('Kermit')
|
9
|
+
end
|
10
|
+
|
11
|
+
context('being played with one movie') do
|
12
|
+
before do
|
13
|
+
@initial_rank = 10
|
14
|
+
@movie = Movie.new('goonies',@initial_rank)
|
15
|
+
@playlist.add_movie(@movie)
|
16
|
+
end
|
17
|
+
|
18
|
+
it('gives the movie a thumbs up if a high number is rolled') do
|
19
|
+
allow(WaldorfAndStatler).to receive(:roll_die).and_return(5)
|
20
|
+
@playlist.play(1)
|
21
|
+
|
22
|
+
expect(@movie.rank).to eq(@initial_rank + 1)
|
23
|
+
end
|
24
|
+
|
25
|
+
it('skips the movie if medium number is rolled') do
|
26
|
+
allow(WaldorfAndStatler).to receive(:roll_die).and_return(4)
|
27
|
+
@playlist.play(1)
|
28
|
+
|
29
|
+
expect(@movie.rank).to eq(@initial_rank)
|
30
|
+
end
|
31
|
+
|
32
|
+
it('gives the movie a thumbs down if low number is rolled') do
|
33
|
+
allow(WaldorfAndStatler).to receive(:roll_die).and_return(0)
|
34
|
+
@playlist.play(1)
|
35
|
+
|
36
|
+
expect(@movie.rank).to eq(@initial_rank - 1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flicks1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- pragmatic_studio_student
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-20 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: Just practicing making gem
|
28
|
+
email: practice@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
|
+
- lib/flicks/inheritance.rb
|
39
|
+
- lib/flicks/movie.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:
|
47
|
+
licenses:
|
48
|
+
- THIS IS MY LICENSE. :)
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '1.9'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.2.2
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Quick practice on creating gem
|
70
|
+
test_files:
|
71
|
+
- spec/flicks/movie_spec.rb
|
72
|
+
- spec/flicks/playlist_spec.rb
|