-
Notifications
You must be signed in to change notification settings - Fork 0
ready for checking commit #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Dzemlianoi
wants to merge
5
commits into
master
Choose a base branch
from
ready_branch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| --- | ||
| :authors: | ||
| - &1 !ruby/object:Author | ||
| name: J. Roaling | ||
| biography: Hi | ||
| - &2 !ruby/object:Author | ||
| name: S. King | ||
| biography: Hello | ||
| - &3 !ruby/object:Author | ||
| name: M. Molier | ||
| biography: Hello | ||
| - &4 !ruby/object:Author | ||
| name: G. Martin | ||
| biography: Hello | ||
| - &5 !ruby/object:Author | ||
| name: M. Tven | ||
| biography: Hello | ||
| - !ruby/object:Author | ||
| name: F. Kafka | ||
| biography: Hello | ||
| - &6 !ruby/object:Author | ||
| name: R. Somsmert | ||
| biography: Hello | ||
| :books: | ||
| - !ruby/object:Book | ||
| title: Harry Potter I | ||
| author: *1 | ||
| - &8 !ruby/object:Book | ||
| title: Harry Potter II | ||
| author: *1 | ||
| - &10 !ruby/object:Book | ||
| title: Harry Potter III | ||
| author: *1 | ||
| - &12 !ruby/object:Book | ||
| title: Dark Tower | ||
| author: *2 | ||
| - &14 !ruby/object:Book | ||
| title: Mizo | ||
| author: *3 | ||
| - &15 !ruby/object:Book | ||
| title: Game of thrones I | ||
| author: *4 | ||
| - !ruby/object:Book | ||
| title: Tom Sawyer | ||
| author: *5 | ||
| - !ruby/object:Book | ||
| title: All about us | ||
| author: *6 | ||
| :readers: | ||
| - &16 !ruby/object:Reader | ||
| name: Denis | ||
| email: dzem@gmail.com | ||
| city: Dnipro | ||
| street: GS | ||
| house: 140 | ||
| - &9 !ruby/object:Reader | ||
| name: Test | ||
| email: test@gmail.com | ||
| city: Kiev | ||
| street: KM | ||
| house: 101 | ||
| - &11 !ruby/object:Reader | ||
| name: Testovskiy | ||
| email: testovskiy@gmail.com | ||
| city: Uzhgorod | ||
| street: KL | ||
| house: 22 | ||
| - &13 !ruby/object:Reader | ||
| name: Testarius | ||
| email: testarius@gmail.com | ||
| city: Odessa | ||
| street: BH | ||
| house: 71 | ||
| - &7 !ruby/object:Reader | ||
| name: Testevich | ||
| email: testarich@gmail.com | ||
| city: Kharkiv | ||
| street: YM | ||
| house: 41 | ||
| :orders: | ||
| - !ruby/object:Order | ||
| reader: *7 | ||
| book: *8 | ||
| date: 2016-10-19 | ||
| - !ruby/object:Order | ||
| reader: *9 | ||
| book: *10 | ||
| date: 2016-10-19 | ||
| - !ruby/object:Order | ||
| reader: *11 | ||
| book: *12 | ||
| date: 2016-10-19 | ||
| - !ruby/object:Order | ||
| reader: *13 | ||
| book: *14 | ||
| date: 2016-10-19 | ||
| - !ruby/object:Order | ||
| reader: *7 | ||
| book: *15 | ||
| date: 2016-10-19 | ||
| - !ruby/object:Order | ||
| reader: *7 | ||
| book: *12 | ||
| date: 2016-10-19 | ||
| - !ruby/object:Order | ||
| reader: *16 | ||
| book: *12 | ||
| date: 2016-10-19 | ||
| - !ruby/object:Order | ||
| reader: *13 | ||
| book: *12 | ||
| date: 2016-10-19 | ||
| - !ruby/object:Order | ||
| reader: *11 | ||
| book: *10 | ||
| date: 2016-10-19 | ||
| - !ruby/object:Order | ||
| reader: *9 | ||
| book: *8 | ||
| date: 2016-10-19 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| require 'yaml' | ||
| Dir['./lib/*.rb'].each { |file| require file } | ||
|
|
||
| library = Library.new | ||
| library.load('library') | ||
| author1 = Author.new('J. Roaling', 'Hi') | ||
| author2 = Author.new('S. King', 'Hello') | ||
| author3 = Author.new('M. Molier', 'Hello') | ||
| author4 = Author.new('G. Martin', 'Hello') | ||
| author5 = Author.new('M. Tven', 'Hello') | ||
| author6 = Author.new('F. Kafka', 'Hello') | ||
| author7 = Author.new('R. Somsmert', 'Hello') | ||
| # | ||
| book = Book.new('Harry Potter I', author1) | ||
| book1 = Book.new('Harry Potter II', author1) | ||
| book2 = Book.new('Harry Potter III', author1) | ||
| book3 = Book.new('Dark Tower', author2) | ||
| book4 = Book.new('Mizo', author3) | ||
| book5 = Book.new('Game of thrones I', author4) | ||
| book6 = Book.new('Game of thrones II', author4) | ||
| book6 = Book.new('Tom Sawyer', author5) | ||
| book7 = Book.new('All about us', author7) | ||
| # | ||
| reader1 = Reader.new('Denis', 'dzem@gmail.com', 'Dnipro', 'GS', 140) | ||
| reader2 = Reader.new('Test', 'test@gmail.com', 'Kiev', 'KM', 101) | ||
| reader3 = Reader.new('Testovskiy', 'testovskiy@gmail.com', 'Uzhgorod', 'KL', 22) | ||
| reader4 = Reader.new('Testarius', 'testarius@gmail.com', 'Odessa', 'BH', 71) | ||
| reader5 = Reader.new('Testevich', 'testarich@gmail.com', 'Kharkiv', 'YM', 41) | ||
| # | ||
| library.add( | ||
| author1, author2, author3, author4, author5, author6, author7, | ||
| book, book1, book2, book3, book4, book5, book6, book7, | ||
| reader1, reader2, reader3, reader4, reader5 | ||
| ) | ||
| # | ||
| order = Order.new(library.readers[0], library.books[0]) | ||
| order1 = Order.new(library.readers[4], library.books[1]) | ||
| order2 = Order.new(library.readers[1], library.books[2]) | ||
| order3 = Order.new(library.readers[2], library.books[3]) | ||
| order4 = Order.new(library.readers[3], library.books[4]) | ||
| order5 = Order.new(library.readers[4], library.books[5]) | ||
| order6 = Order.new(library.readers[4], library.books[3]) | ||
| order7 = Order.new(library.readers[0], library.books[3]) | ||
| order8 = Order.new(library.readers[3], library.books[3]) | ||
| order9 = Order.new(library.readers[2], library.books[2]) | ||
| order10 = Order.new(library.readers[1], library.books[1]) | ||
| order11 = Order.new(library.readers[4], library.books[3]) | ||
|
|
||
| library.save('library') | ||
|
|
||
| puts library.top_reader.name | ||
| puts library.top_book.title | ||
| puts library.top_books_statistics(12) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| class Author | ||
| attr_accessor :name, :biography | ||
|
|
||
| def initialize(name, biography = 'No biography yet') | ||
| @name = name | ||
| @biography = biography | ||
| end | ||
|
|
||
| def ==(other) | ||
| name == other.name if other.instance_of? Author | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| class Book | ||
| attr_accessor :title, :author | ||
|
|
||
| def initialize(title, author) | ||
| @title = title | ||
| @author = author | ||
| end | ||
|
|
||
| def ==(other) | ||
| check_author(other) && check_title(other) if other.is_a? Book | ||
| end | ||
|
|
||
| def check_author(other) | ||
| author == other.author | ||
| end | ||
|
|
||
| def check_title(other) | ||
| title == other.title | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| class Library | ||
| include Loader | ||
| attr_accessor :authors, :readers, :books, :orders | ||
|
|
||
| def initialize | ||
| @authors = [] | ||
| @books = [] | ||
| @readers = [] | ||
| @orders = [] | ||
| end | ||
|
|
||
| def add(name, *items, username) | ||
| items.each do |item| | ||
| case item | ||
| when Book | ||
| books.push(item) if !books.include?(item) && authors.include?(item.author) | ||
| when Order | ||
| orders.push(item) if readers.include?(item.reader) && books.include?(item.book) | ||
| when Reader | ||
| readers.push(item) unless readers.include?(item) | ||
| when Author | ||
| authors.push(item) unless authors.include?(item) | ||
| else | ||
| raise 'Undefined element' | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def top_reader | ||
| sort_by(:reader).first | ||
| end | ||
|
|
||
| def top_book | ||
| sort_by(:book).first | ||
| end | ||
|
|
||
| def top_books_statistics(number) | ||
| raise 'Annormal quantity of books' if number > orders.count | ||
| top_n_books = sort_by(:book, number) | ||
| top_n_books.map{|(_,orders)| orders}.flatten.map(&:reader).uniq.count | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def sort_by(by, quantity = nil) | ||
| orders.group_by(&by).max_by(quantity){|_, orders| orders.count} | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| module Loader | ||
| BACKUP_NAME = 'data' | ||
| PATH = './data/' | ||
| EXTENSION = '.yml' | ||
|
|
||
| def load(file_name = BACKUP_NAME) | ||
| file_name += EXTENSION.to_s | ||
| pull_data(file_name) if File.exist?(PATH + file_name) | ||
| end | ||
|
|
||
| def aquire_data | ||
| { | ||
| authors: @authors, | ||
| books: @books, | ||
| readers: @readers, | ||
| orders: @orders | ||
| } | ||
| end | ||
|
|
||
| def pull_data(filename) | ||
| file = File.open(PATH + filename) | ||
| data = YAML.load(file) | ||
| @authors = data[:authors] | ||
| @books = data[:books] | ||
| @readers = data[:readers] | ||
| @orders = data[:orders] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we unify this |
||
| file.close | ||
| end | ||
|
|
||
| def save(file_name = BACKUP_NAME) | ||
| full_path = PATH.to_s + file_name.to_s + EXTENSION | ||
| data = YAML.dump(aquire_data) | ||
| File.new(full_path, 'w') unless File.exist?(full_path) | ||
| File.write(full_path, data) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| class Order | ||
| attr_accessor :reader, :book, :date | ||
|
|
||
| def initialize(reader, book, date = Date.today) | ||
| raise 'Unnormed data' unless reader.instance_of?(Reader) && book.instance_of?(Book) | ||
| @reader = reader | ||
| @book = book | ||
| @date = date | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| class Reader | ||
| attr_accessor :name, :email, :city, :street, :house | ||
|
|
||
| def initialize(name, email, city, street, house) | ||
| @name = name | ||
| @email = email | ||
| @city = city | ||
| @street = street | ||
| @house = house | ||
| end | ||
|
|
||
| def ==(other) | ||
| @email == other.email if other.instance_of?Reader | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use without local here