-
Notifications
You must be signed in to change notification settings - Fork 0
/
movie.rb
92 lines (83 loc) · 2.64 KB
/
movie.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# frozen_string_literal: true
module Kino
require 'date'
# Class Movie, the source of 4 child classes
class Movie
attr_reader :link, :title, :year, :country,
:date, :genre, :duration, :rating,
:director, :main_actors, :collection
def initialize(link, title, year, country,
date, genre, duration, rating,
director, main_actors, collection)
@link = link
@title = title
@year = year.to_i
@country = country
@date = case date.split('-').size
when 3
Date.parse(date)
when 2
Date.strptime(date, '%Y-%m')
when 1
Date.strptime(date, '%Y')
end
@genre = genre.split(',')
@duration = duration.to_i
@rating = rating.to_f
@director = director
@main_actors = main_actors.split(',')
@collection = collection
end
def month
Date::MONTHNAMES[@date.month.to_i] if @date.month
end
def genre?(value)
raise ArgumentError, "Error. There's no such genre: \"#{value}\"."\
unless @collection.genres.include?(value)
genre.include?(value)
end
def actor?(value)
@actor.include?(value)
end
def matches?(key, val)
if send(key).is_a?(Array)
send(key).include?(val)
else
val === send(key)
end
end
def self.create(link, title, year, country,
date, genre, duration, rating,
director, main_actors, collection)
case year.to_i
when (1900...1945)
AncientMovie.new(link, title, year, country,
date, genre, duration, rating,
director, main_actors, collection)
when (1945...1968)
ClassicMovie.new(link, title, year, country,
date, genre, duration, rating,
director, main_actors, collection)
when (1968...2000)
ModernMovie.new(link, title, year, country,
date, genre, duration, rating,
director, main_actors, collection)
else
NewMovie.new(link, title, year, country,
date, genre, duration, rating,
director, main_actors, collection)
end
end
def period
# self.class.name.sub(/Movie/,'').downcase
self.class.name.sub(/Movie/, '').sub(/Kino::/, '').downcase
end
def price
Money.from_amount(self.class::PRICE, 'USD')
end
end
require './ancient_movie.rb'
require './classic_movie.rb'
require './modern_movie.rb'
require './new_movie.rb'
end