flicks_ex_PS 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.txt +23 -0
- data/README.md +22 -0
- data/bin/flicks +38 -0
- data/bin/movies.csv +3 -0
- data/lib/flicks/movie.rb +45 -0
- data/lib/flicks/movie3d.rb +39 -0
- data/lib/flicks/playlist.rb +97 -0
- data/lib/flicks/rankable.rb +11 -0
- data/lib/flicks/snackbar.rb +20 -0
- metadata +48 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 006a4c7262e0eeaa792f61f8c2159d05a0236a4efce1de1b1fea70780a4fe58b
|
|
4
|
+
data.tar.gz: 1960a877992585a2e9a1cf57fa99768dadd03ca07711ba75aaa467e1f7ec02c9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 77caf1200b56a2c37aa59ec1b7c32325d005e2ad1543e7e250e07be90cd33d2378b0188c3881c84a55568343be8e88f156d7d17a330932c55e3e0d574f95cbbb
|
|
7
|
+
data.tar.gz: ed8a24cd49de9c2dfe58d3987262dd5c47dba6a25f35c385ac2b7fff727812d3ba95c9a89f6aadf3b8497a8f601a3e9b6de1fb419f85d95112bddb54b93f0620
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 The Pragmatic Studio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
- You may not use this Software in other training contexts.
|
|
13
|
+
|
|
14
|
+
- The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Flicks
|
|
2
|
+
|
|
3
|
+
This is an example application used in The Pragmatic Studio's
|
|
4
|
+
[Ruby video course](https://pragmaticstudio.com/courses/ruby).
|
|
5
|
+
|
|
6
|
+
## Usage
|
|
7
|
+
|
|
8
|
+
To run the example main program file, use:
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
flicks
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
You can also specify a CSV file with movie titles and ranks:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
flicks my_movies.csv
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
This code is available as open source under the terms of the LICENSE.txt file.
|
data/bin/flicks
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative "../lib/flicks/playlist"
|
|
4
|
+
|
|
5
|
+
playlist_1 = Flicks::Playlist.new("Kermit")
|
|
6
|
+
|
|
7
|
+
movies_file = File.join(__dir__, "movies.csv")
|
|
8
|
+
|
|
9
|
+
ARGV[0]
|
|
10
|
+
|
|
11
|
+
playlist_1.load(ARGV.shift || movies_file)
|
|
12
|
+
|
|
13
|
+
loop do
|
|
14
|
+
print "\nHow many viewings? ('quit' to exit) "
|
|
15
|
+
|
|
16
|
+
answer = gets.chomp.downcase
|
|
17
|
+
|
|
18
|
+
case answer
|
|
19
|
+
when /^\d+$/
|
|
20
|
+
playlist_1.play(answer.to_i)
|
|
21
|
+
when "quit", "exit"
|
|
22
|
+
playlist_1.print_stats
|
|
23
|
+
break
|
|
24
|
+
else
|
|
25
|
+
puts "Please enter a number or 'quit'"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
playlist_1.save
|
|
30
|
+
|
|
31
|
+
# playlist_2 = Playlist.new("Fozzie")
|
|
32
|
+
# playlist_2.add_movie(movie_3)
|
|
33
|
+
|
|
34
|
+
# movie_4 = Movie.new("gremlins", 7)
|
|
35
|
+
# playlist_2.add_movie(movie_4)
|
|
36
|
+
|
|
37
|
+
# playlist_2.play(20)
|
|
38
|
+
# playlist_1.print_stats
|
data/bin/movies.csv
ADDED
data/lib/flicks/movie.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require_relative "rankable"
|
|
2
|
+
|
|
3
|
+
module Flicks
|
|
4
|
+
class Movie
|
|
5
|
+
include Rankable
|
|
6
|
+
|
|
7
|
+
attr_reader :snacks_eaten
|
|
8
|
+
attr_accessor :title, :rank
|
|
9
|
+
|
|
10
|
+
def initialize(title, rank = 5)
|
|
11
|
+
@title = title.capitalize
|
|
12
|
+
@rank = rank
|
|
13
|
+
@snacks_eaten = Hash.new(0)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def add_snack(name, price)
|
|
17
|
+
@snacks_eaten[name] += price
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def total_snack_price
|
|
21
|
+
@snacks_eaten.values.sum
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.from_csv(line)
|
|
25
|
+
title, rank = line.split(",")
|
|
26
|
+
Movie.new(title, Integer(rank))
|
|
27
|
+
rescue ArgumentError
|
|
28
|
+
puts "Ignored invalid rank: #{rank}"
|
|
29
|
+
Movie.new(title)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def to_csv
|
|
33
|
+
"#{@title},#{@rank}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def to_s
|
|
37
|
+
"#{@title} has a rank of #{@rank}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
if __FILE__ == $0
|
|
42
|
+
movie = Movie.new("Star Wars", 10)
|
|
43
|
+
puts movie
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require_relative "movie"
|
|
2
|
+
|
|
3
|
+
module Flicks
|
|
4
|
+
class Movie3D < Movie
|
|
5
|
+
|
|
6
|
+
def initialize (title, rank, wow_factor)
|
|
7
|
+
super(title, rank)
|
|
8
|
+
@wow_factor = wow_factor
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show_effect
|
|
12
|
+
puts "Wow! " * @wow_factor
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def thumbs_up
|
|
16
|
+
@wow_factor.times { super }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
if __FILE__ == $0
|
|
23
|
+
|
|
24
|
+
movie3d = Movie3D.new("godzilla", 7, 10)
|
|
25
|
+
|
|
26
|
+
puts movie3d.title
|
|
27
|
+
puts movie3d.rank
|
|
28
|
+
|
|
29
|
+
movie3d.show_effect
|
|
30
|
+
|
|
31
|
+
movie3d.thumbs_up
|
|
32
|
+
|
|
33
|
+
puts movie3d
|
|
34
|
+
|
|
35
|
+
puts Movie3D.superclass
|
|
36
|
+
|
|
37
|
+
p Movie3D.ancestors
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require_relative "snackbar"
|
|
2
|
+
require_relative "movie"
|
|
3
|
+
|
|
4
|
+
module Flicks
|
|
5
|
+
class Playlist
|
|
6
|
+
|
|
7
|
+
attr_reader :name, :movies
|
|
8
|
+
|
|
9
|
+
def initialize(name)
|
|
10
|
+
@name = name
|
|
11
|
+
@movies = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def load(from_file)
|
|
15
|
+
File.readlines(from_file, chomp: true).each do |line|
|
|
16
|
+
movie = Movie.from_csv(line)
|
|
17
|
+
add_movie(movie)
|
|
18
|
+
end
|
|
19
|
+
rescue Errno::ENOENT
|
|
20
|
+
puts "Whoops, #{from_file} not found!"
|
|
21
|
+
exit 1
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def save(to_file = "movie_rankings.csv")
|
|
25
|
+
File.open(to_file, "w") do |file|
|
|
26
|
+
sorted_movies.each do |movie|
|
|
27
|
+
file.puts movie.to_csv
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def add_movie(movie)
|
|
33
|
+
@movies << movie
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def roll_die
|
|
37
|
+
rand(1..6)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def sorted_movies
|
|
41
|
+
@movies.sort_by {|movie| movie.rank}.reverse
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def print_stats
|
|
45
|
+
puts "\n#{@name}'s Playlist Stats:"
|
|
46
|
+
puts "-" * 30
|
|
47
|
+
|
|
48
|
+
puts sorted_movies
|
|
49
|
+
|
|
50
|
+
@movies.each do |movie|
|
|
51
|
+
puts "\n#{movie.title} snack totals:"
|
|
52
|
+
movie.snacks_eaten.each do |name, total_price|
|
|
53
|
+
puts "#{name}: $#{total_price}"
|
|
54
|
+
end
|
|
55
|
+
puts "total: $#{movie.total_snack_price}"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def play(viewings = 3)
|
|
60
|
+
puts "*" * 30
|
|
61
|
+
puts "#{@name}'s playlist:"
|
|
62
|
+
|
|
63
|
+
puts "\nThe snackbar has:"
|
|
64
|
+
menu_items = Snackbar.menu_items
|
|
65
|
+
|
|
66
|
+
puts menu_items
|
|
67
|
+
|
|
68
|
+
puts "\nBefore watching:"
|
|
69
|
+
puts @movies
|
|
70
|
+
|
|
71
|
+
1.upto(viewings) do |viewing_number|
|
|
72
|
+
puts "\nViewing #{viewing_number}"
|
|
73
|
+
@movies.each do |movie|
|
|
74
|
+
number_rolled = roll_die
|
|
75
|
+
|
|
76
|
+
case number_rolled
|
|
77
|
+
when 1..2
|
|
78
|
+
movie.thumbs_down
|
|
79
|
+
puts "#{movie.title} got a 👎"
|
|
80
|
+
when 3..4
|
|
81
|
+
puts "#{movie.title} got skipped"
|
|
82
|
+
else
|
|
83
|
+
movie.thumbs_up
|
|
84
|
+
puts "#{movie.title} got a 👍"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
snack = Snackbar.random_snack
|
|
88
|
+
movie.add_snack(snack.name, snack.price)
|
|
89
|
+
puts "During #{movie.title}, #{@name} ate #{snack.name} for $#{snack.price}"
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
puts "\nAfter watching"
|
|
94
|
+
puts @movies
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Flicks
|
|
2
|
+
module Snackbar
|
|
3
|
+
Snack = Data.define(:name, :price)
|
|
4
|
+
|
|
5
|
+
SNACKS = [
|
|
6
|
+
Snack.new("popcorn", 3),
|
|
7
|
+
Snack.new("candy", 1),
|
|
8
|
+
Snack.new("nachos", 4),
|
|
9
|
+
Snack.new("pretzels", 2)
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
def self.random_snack
|
|
13
|
+
SNACKS.sample
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.menu_items
|
|
17
|
+
SNACKS.map { |snack| "#{snack.name} for $#{snack.price}" }
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: flicks_ex_PS
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tania Ramirez
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
email: tregina7018@gmail.com
|
|
13
|
+
executables:
|
|
14
|
+
- flicks
|
|
15
|
+
extensions: []
|
|
16
|
+
extra_rdoc_files: []
|
|
17
|
+
files:
|
|
18
|
+
- LICENSE.txt
|
|
19
|
+
- README.md
|
|
20
|
+
- bin/flicks
|
|
21
|
+
- bin/movies.csv
|
|
22
|
+
- lib/flicks/movie.rb
|
|
23
|
+
- lib/flicks/movie3d.rb
|
|
24
|
+
- lib/flicks/playlist.rb
|
|
25
|
+
- lib/flicks/rankable.rb
|
|
26
|
+
- lib/flicks/snackbar.rb
|
|
27
|
+
homepage: https://pragmaticstudio.com
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata: {}
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: 3.2.0
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubygems_version: 3.6.7
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: Flicks exercise from The Pragmatic Studio
|
|
48
|
+
test_files: []
|