Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1138ee2
task10 complete
devico Oct 13, 2016
0da845b
Task11
devico Oct 13, 2016
a738850
сделал структуру каталогов и подкорректировал код
devico Oct 14, 2016
9f8c74a
переделал структуру и код, внес исправления по замечаниям
devico Oct 15, 2016
362f00d
переименовал файлы примеров, убрал множественные require
devico Oct 15, 2016
723f903
обновленный код
devico Oct 15, 2016
541172d
код работает, тесты работают
devico Oct 16, 2016
4d74827
заменил пути в спеках на константу и включил файлы в модуль TopMovies
devico Oct 16, 2016
8c026b9
создал файл readme.md
devico Oct 20, 2016
75a5054
внес изменения согласно замечаний
devico Oct 21, 2016
876c40c
попытка объединить usage и examples
devico Oct 21, 2016
61b0ed0
еще одна попытка представления файла README
devico Oct 22, 2016
a8142ff
исправил форматирование файла README
devico Oct 22, 2016
c19a11b
первая версия документирования кода
devico Oct 23, 2016
f7d1f02
сделал комментарии к файлу theatre.rb
devico Oct 24, 2016
81572fe
Delete checksums
devico Oct 24, 2016
4ff586f
add folder
devico Oct 24, 2016
4456ad4
Merge branch 'task11' of https://github.com/devico/learning-ruby into…
devico Oct 24, 2016
d429f62
delete folder
devico Oct 24, 2016
5cf6607
delete .yardoc
devico Oct 24, 2016
c675210
delete doc
devico Oct 24, 2016
ef794f8
внес исправления в комментарии
devico Oct 24, 2016
64ccd82
сделал исполняемый файл в папке bin/ , работает
devico Oct 26, 2016
357d4fa
установил bundler, переделал файл bin/netflix
devico Oct 27, 2016
cd29b8c
bin/netflix поправил фильтр year
devico Oct 28, 2016
4eccade
добавил информацию об исполняемом файле в README.md
devico Oct 28, 2016
fac3665
создал файл .gemspec и сделал gem
devico Oct 28, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.yardoc/
/doc/
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
AllCops:
Exclude:
- spec/*.rb
TargetRubyVersion: 2.0
Documentation:
Enabled: false
ParameterLists:
Expand Down
3 changes: 3 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--private
--protected
-o doc/ruby
14 changes: 14 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true
source "https://rubygems.org"

gem 'rspec', :require => 'spec'
gem 'money'
gem 'rubocop'
gem 'virtus'
gem 'nokogiri'
gem 'webmock'
gem 'vcr'
gem 'themoviedb'
gem 'haml'
gem 'yard'
gem 'thor'
93 changes: 93 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.4.0)
ast (2.3.0)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
ice_nine (~> 0.11.0)
thread_safe (~> 0.3, >= 0.3.1)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
crack (0.4.3)
safe_yaml (~> 1.0.0)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.2.5)
equalizer (0.0.11)
haml (4.0.7)
tilt
hashdiff (0.3.0)
httparty (0.14.0)
multi_xml (>= 0.5.2)
i18n (0.7.0)
ice_nine (0.11.2)
mini_portile2 (2.1.0)
money (6.7.1)
i18n (>= 0.6.4, <= 0.7.0)
sixarm_ruby_unaccent (>= 1.1.1, < 2)
multi_xml (0.5.5)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
parser (2.3.1.4)
ast (~> 2.2)
powerpack (0.1.1)
rainbow (2.1.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
rubocop (0.44.1)
parser (>= 2.3.1.1, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.8.1)
safe_yaml (1.0.4)
sixarm_ruby_unaccent (1.1.1)
themoviedb (1.0.1)
httparty
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.5)
unicode-display_width (1.1.1)
vcr (3.0.3)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
descendants_tracker (~> 0.0, >= 0.0.3)
equalizer (~> 0.0, >= 0.0.9)
webmock (2.1.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff
yard (0.9.5)

PLATFORMS
ruby

DEPENDENCIES
haml
money
nokogiri
rspec
rubocop
themoviedb
thor
vcr
virtus
webmock
yard

BUNDLED WITH
1.13.6
204 changes: 204 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
TopMovies
========

TopMovies is a console application to manipulate the data from the list of top 250 IMDB movies.
Usage
==========

Installation
-------------------
$ gem install topmovies

Before you can use all the features of the library you want to connect a data file with movies

```ruby
file_name = ARGV[0] || '../lib/topmovies/data/movies.txt'
if File.exist?(file_name)
File.open(file_name)
else
puts 'Ошибка. Файл отсутствует!'
exit
end
```

####MovieCollection

MovieCollection, created in the application, allows you to extract data and show filtered and sorted lists of movies, based on different criteria, also it can display any statistics on films.

```ruby
# make collection of movies
movies = TopMovies::MovieCollection.new(file_name)
# => <TopMovies::MovieCollection:0x00000002ab6da8>

#show comedies
movies.filter(genre: 'Comedy')
# => <TopMovies::ModernMovie:0x00000002ff7038>
# => <TopMovies::AncientMovie:0x00000002fdcaa8>
# => <TopMovies::NewMovie:0x00000002fd5ca8>
# => ...

# show sorted list movies by year
movies.sort_by(:year)
# => The Kid - 1921
# => The Gold Rush - 1925
# => The General - 1926
# => Metropolis - 1927
# => ...

# show count of movies maked each author
movies.stats(:author)
# => {"Adam Elliot"=>1, "Akira Kurosawa"=>6, "Alejandro González Iñárritu"=>1, ... }

# get first movie
movie = movies.all.first

# number famous actors played in this movie
movie.actors.count
# => 3

# Arnold Shwarzenegger played in this movie
movie.actors.include?('Arnold Shwarzenegger')
# => false
```

####Cinema

Netflix and Theatre are cinemas based on MovieCollection have cashboxes that can accept payments and sell tickets.

#####Netflix

```ruby
# make online cinema Netflix
online = TopMovies::Netflix.new(file_name)
# => #<TopMovies::Netflix:0x000000021e0558>

# show newest Drama
online.show(genre: 'Drama', period: :new)
# => Downfall — новинка, вышло 12 лет назад!

# create component filter
movies = online.show do |movie|
!movie.title.include?('Terminator') && \
movie.genre[0].include?('Action') && \
movie.year > 2003
end
# genre of movies is Action and not have Terminator and newer 2003
# => Elite Squad: The Enemy Within — новинка, вышло 6 лет назад!

# put cash to cashbox of Netflix
online.pay(35)
# => 35.00
```

#####Theatre

```ruby
# make usual cinema Theatre
theatre =
TopMovies::Theatre.new do
hall :red, title: 'Красный зал', places: 100
hall :blue, title: 'Синий зал', places: 50
hall :green, title: 'Зелёный зал (deluxe)', places: 12

period '09:00'..'12:00' do
description 'Утренний сеанс'
filters genre: 'Comedy', year: 1900..1980
price 10
hall :red, :blue
end

period '12:00'..'16:00' do
description 'Спецпоказ'
title 'The Terminator'
price 50
hall :green
end

period '16:00'..'20:00' do
description 'Вечерний сеанс'
filters genre: %w(Action Drama), year: 2007..Time.now.year
price 20
hall :red, :blue
end

period '19:00'..'22:00' do
description 'Вечерний сеанс для киноманов'
filters year: 1900..1945, exclude_country: 'USA'
price 30
hall :green
end
end
# => <TopMovies::Netflix:0x000000011152a0>

# you can add period into Theatre
theatre.period '21:00'..'23:00' do
description 'Еще один сеанс'
filters genre: 'Sci-Fi', year: 1900..1980
price 13
hall :red
end

# you can buy a ticket
theatre.buy_ticket('10:20')
# => Утренний сеанс - 09:00..12:00 : Фильм: The Gold Rush - 10.00 ₴
theatre.buy_ticket('13:20')
# => Спецпоказ - 12:00..16:00 : Фильм: The Terminator - 50.00 ₴
theatre.buy_ticket('17:20')
# => Вечерний сеанс - 16:00..20:00 : Фильм: Interstellar - 20.00 ₴
theatre.buy_ticket('19:20', hall: :green)
# => Вечерний сеанс для киноманов - 19:00..22:00 : Фильм: The Maltese Falcon - 30.00 ₴

# if you want you can check the money in cashbox of Theatre
theatre.cash
# => 110.00

# yet you can spend cash collection into cashbox of Theatre
theatre.take('Bank')
# => Проведена инкассация
# => 0.00

```
####Additional info

In addition, the application can get the budget for each film with IMDb site, extract the posters and film title translation into other languages with TMDB site, and renders html page with all the movies.

```ruby
# get the film's budget
movie = movies.all[112]
movie.budget
# => $14,400,000

# get a poster for the film
movie = movies.filter(title: 'Terminator')
movie.poster


# receive translations of the film in other language
movie = movies.filter(title: '12 Angry Men')
movie.translations

# create HTML markup
movies.render_html
# => html markup
```

####Run library from CLI

There is an executable file (bin/netflix), which can be run from the command line
  passing it parameters, and receive the filtered data.

```ruby
# run
$ bin/netflix netflix --pay 25 --show genre:Comedy
# => 25.00
# => The General — старый фильм (1926 год)
$ bin/netflix netflix --pay 25 --show year:1988
# => 25.00
# => The General — старый фильм (1926 год)
```

Other methods for manipulating data list IMDB top 250 films described to documentation

Author
--------------
Serhii Dmytrakov <clamdm@mail.ru>
22 changes: 22 additions & 0 deletions bin/netflix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env ruby
require "thor"
require_relative '../lib/topmovies/movie'
require_relative '../lib/topmovies/ancient_movie'
require_relative '../lib/topmovies/classic_movie'
require_relative '../lib/topmovies/modern_movie'
require_relative '../lib/topmovies/new_movie'
require_relative '../lib/topmovies/movie_collection'
require_relative '../lib/topmovies/netflix'

class MyCLI < Thor
desc "Preview Movie", "pay to show movie"
option :pay, :type => :numeric, :required => true
option :show, :type => :hash, :required => true
def netflix
online = TopMovies::Netflix.new('lib/topmovies/data/movies.txt')
puts online.pay(options[:pay]) if options[:pay]
puts online.show(options[:show]) if options[:show]
end
end

MyCLI.start
Loading