{"action":"created","comment":{"url":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/comments/90668028","pull_request_review_id":11187309,"id":90668028,"diff_hunk":"@@ -0,0 +1,183 @@\n+models = File.absolute_path(\"models\")\n+Dir.glob(File.join(models, \"*.rb\")).each do |file|\n+  require_relative file\n+end\n+\n+require 'csv'\n+\n+module Application\n+\n+  class Library\n+\n+    def initialize\n+      @books, @orders, @readers, @authors = [], [], [], []\n+    end\n+\n+    #-------------------------\n+\n+    def add_books(*books)\n+      author_ids = @authors.map { |author| author.id }\n+      for book in books.flatten\n+        if author_ids.include? book.author.id\n+          @books.push book\n+        else\n+          puts \"#{book} book's author not found\"\n+        end\n+      end\n+    end\n+\n+    def register_readers(*readers)\n+      @readers.push *readers.flatten\n+    end\n+\n+    def make_orders(*orders)\n+      reader_ids = @readers.map { |reader| reader.id }\n+      book_ids = @books.map { |book| book.id }\n+      for order in orders.flatten\n+        has_reader = reader_ids.include?(order.reader.id)\n+        has_book = book_ids.include?(order.book.id)\n+        if has_reader && has_book\n+          @orders.push order\n+        else\n+          puts \"#{order.reader} not found\" unless has_reader\n+          puts \"#{order.book} not found\" unless has_book\n+        end\n+      end\n+    end\n+\n+    def register_authors(*authors)\n+      @authors.push *authors.flatten\n+    end\n+\n+    #-------------------------\n+\n+    def reader_by_id reader_id\n+      @readers.select { |reader| reader.id == reader_id }.first\n+    end\n+\n+    def author_by_id author_id\n+      @authors.select { |author| author.id == author_id }.first\n+    end\n+\n+    def book_by_id book_id\n+      @books.select { |book| book.id == book_id }.first\n+    end\n+\n+    #-------------------------\n+\n+    [:books,:orders,:readers,:authors].each do |method|\n+      define_method method do\n+        array = case method\n+                  when :books\n+                    @books\n+                  when :orders\n+                    @orders\n+                  when :readers\n+                    @readers\n+                  when :authors\n+                    @authors\n+                  else\n+                    nil\n+                end\n+        Array.new array\n+      end\n+    end\n+\n+    #-------------------------\n+\n+    def frequent_reader\n+      reader = @orders.group_by { |order| order.reader }.max_by { |order| order[1].count }[0]\n+      puts \"Most active user is #{reader.name} with Id=#{reader.id}\"\n+    end\n+\n+    def most_popular_book\n+      book = @orders.group_by { |order| order.book }.max_by { |order| order[1].count }[0]\n+      puts \"Most popular book is #{book.title} from #{book.author.name} with Id=#{book.id}\"\n+    end\n+\n+    def top3_popular_books\n+      puts \"Top 3 popular books\"\n+\n+      @orders.group_by { |order| order.book }\n+                  .sort_by { |obj| obj[1].count }\n+                  .reverse\n+                  .slice(0..2).each_with_index do |book,index|","path":"library.rb","position":null,"original_position":104,"commit_id":"ea055e6ad7094f7e47844eac9180f41ebf7d8e6d","original_commit_id":"2dffdbef6558defc5b794fd671d8e63b210e58a0","user":{"login":"ne0nx","id":4031133,"avatar_url":"https://avatars.githubusercontent.com/u/4031133?v=3","gravatar_id":"","url":"https://api.github.com/users/ne0nx","html_url":"https://github.com/ne0nx","followers_url":"https://api.github.com/users/ne0nx/followers","following_url":"https://api.github.com/users/ne0nx/following{/other_user}","gists_url":"https://api.github.com/users/ne0nx/gists{/gist_id}","starred_url":"https://api.github.com/users/ne0nx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ne0nx/subscriptions","organizations_url":"https://api.github.com/users/ne0nx/orgs","repos_url":"https://api.github.com/users/ne0nx/repos","events_url":"https://api.github.com/users/ne0nx/events{/privacy}","received_events_url":"https://api.github.com/users/ne0nx/received_events","type":"User","site_admin":false},"body":"replaced to first(3)","created_at":"2016-12-02T16:00:44Z","updated_at":"2016-12-02T16:00:44Z","html_url":"https://github.com/ne0nx/Library-Ruby/pull/2#discussion_r90668028","pull_request_url":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/comments/90668028"},"html":{"href":"https://github.com/ne0nx/Library-Ruby/pull/2#discussion_r90668028"},"pull_request":{"href":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/2","id":89547773,"html_url":"https://github.com/ne0nx/Library-Ruby/pull/2","diff_url":"https://github.com/ne0nx/Library-Ruby/pull/2.diff","patch_url":"https://github.com/ne0nx/Library-Ruby/pull/2.patch","issue_url":"https://api.github.com/repos/ne0nx/Library-Ruby/issues/2","number":2,"state":"open","locked":false,"title":"Add functionality","user":{"login":"ne0nx","id":4031133,"avatar_url":"https://avatars.githubusercontent.com/u/4031133?v=3","gravatar_id":"","url":"https://api.github.com/users/ne0nx","html_url":"https://github.com/ne0nx","followers_url":"https://api.github.com/users/ne0nx/followers","following_url":"https://api.github.com/users/ne0nx/following{/other_user}","gists_url":"https://api.github.com/users/ne0nx/gists{/gist_id}","starred_url":"https://api.github.com/users/ne0nx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ne0nx/subscriptions","organizations_url":"https://api.github.com/users/ne0nx/orgs","repos_url":"https://api.github.com/users/ne0nx/repos","events_url":"https://api.github.com/users/ne0nx/events{/privacy}","received_events_url":"https://api.github.com/users/ne0nx/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-10-17T00:55:37Z","updated_at":"2016-12-02T16:00:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"02ac56bb9b1ea4d05a54d35dd3cc15f99fd8435b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/2/commits","review_comments_url":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/2/comments","review_comment_url":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ne0nx/Library-Ruby/issues/2/comments","statuses_url":"https://api.github.com/repos/ne0nx/Library-Ruby/statuses/ea055e6ad7094f7e47844eac9180f41ebf7d8e6d","head":{"label":"ne0nx:functionality","ref":"functionality","sha":"ea055e6ad7094f7e47844eac9180f41ebf7d8e6d","user":{"login":"ne0nx","id":4031133,"avatar_url":"https://avatars.githubusercontent.com/u/4031133?v=3","gravatar_id":"","url":"https://api.github.com/users/ne0nx","html_url":"https://github.com/ne0nx","followers_url":"https://api.github.com/users/ne0nx/followers","following_url":"https://api.github.com/users/ne0nx/following{/other_user}","gists_url":"https://api.github.com/users/ne0nx/gists{/gist_id}","starred_url":"https://api.github.com/users/ne0nx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ne0nx/subscriptions","organizations_url":"https://api.github.com/users/ne0nx/orgs","repos_url":"https://api.github.com/users/ne0nx/repos","events_url":"https://api.github.com/users/ne0nx/events{/privacy}","received_events_url":"https://api.github.com/users/ne0nx/received_events","type":"User","site_admin":false},"repo":{"id":71086989,"name":"Library-Ruby","full_name":"ne0nx/Library-Ruby","owner":{"login":"ne0nx","id":4031133,"avatar_url":"https://avatars.githubusercontent.com/u/4031133?v=3","gravatar_id":"","url":"https://api.github.com/users/ne0nx","html_url":"https://github.com/ne0nx","followers_url":"https://api.github.com/users/ne0nx/followers","following_url":"https://api.github.com/users/ne0nx/following{/other_user}","gists_url":"https://api.github.com/users/ne0nx/gists{/gist_id}","starred_url":"https://api.github.com/users/ne0nx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ne0nx/subscriptions","organizations_url":"https://api.github.com/users/ne0nx/orgs","repos_url":"https://api.github.com/users/ne0nx/repos","events_url":"https://api.github.com/users/ne0nx/events{/privacy}","received_events_url":"https://api.github.com/users/ne0nx/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ne0nx/Library-Ruby","description":null,"fork":false,"url":"https://api.github.com/repos/ne0nx/Library-Ruby","forks_url":"https://api.github.com/repos/ne0nx/Library-Ruby/forks","keys_url":"https://api.github.com/repos/ne0nx/Library-Ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ne0nx/Library-Ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ne0nx/Library-Ruby/teams","hooks_url":"https://api.github.com/repos/ne0nx/Library-Ruby/hooks","issue_events_url":"https://api.github.com/repos/ne0nx/Library-Ruby/issues/events{/number}","events_url":"https://api.github.com/repos/ne0nx/Library-Ruby/events","assignees_url":"https://api.github.com/repos/ne0nx/Library-Ruby/assignees{/user}","branches_url":"https://api.github.com/repos/ne0nx/Library-Ruby/branches{/branch}","tags_url":"https://api.github.com/repos/ne0nx/Library-Ruby/tags","blobs_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ne0nx/Library-Ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/ne0nx/Library-Ruby/languages","stargazers_url":"https://api.github.com/repos/ne0nx/Library-Ruby/stargazers","contributors_url":"https://api.github.com/repos/ne0nx/Library-Ruby/contributors","subscribers_url":"https://api.github.com/repos/ne0nx/Library-Ruby/subscribers","subscription_url":"https://api.github.com/repos/ne0nx/Library-Ruby/subscription","commits_url":"https://api.github.com/repos/ne0nx/Library-Ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/ne0nx/Library-Ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/ne0nx/Library-Ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/ne0nx/Library-Ruby/contents/{+path}","compare_url":"https://api.github.com/repos/ne0nx/Library-Ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ne0nx/Library-Ruby/merges","archive_url":"https://api.github.com/repos/ne0nx/Library-Ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ne0nx/Library-Ruby/downloads","issues_url":"https://api.github.com/repos/ne0nx/Library-Ruby/issues{/number}","pulls_url":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/ne0nx/Library-Ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/ne0nx/Library-Ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ne0nx/Library-Ruby/labels{/name}","releases_url":"https://api.github.com/repos/ne0nx/Library-Ruby/releases{/id}","deployments_url":"https://api.github.com/repos/ne0nx/Library-Ruby/deployments","created_at":"2016-10-17T00:47:11Z","updated_at":"2016-10-17T00:47:11Z","pushed_at":"2016-11-28T16:36:11Z","git_url":"git://github.com/ne0nx/Library-Ruby.git","ssh_url":"git@github.com:ne0nx/Library-Ruby.git","clone_url":"https://github.com/ne0nx/Library-Ruby.git","svn_url":"https://github.com/ne0nx/Library-Ruby","homepage":null,"size":18,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ne0nx:master","ref":"master","sha":"b529bf6328e5c2ec3324027544ccb200c064d1c9","user":{"login":"ne0nx","id":4031133,"avatar_url":"https://avatars.githubusercontent.com/u/4031133?v=3","gravatar_id":"","url":"https://api.github.com/users/ne0nx","html_url":"https://github.com/ne0nx","followers_url":"https://api.github.com/users/ne0nx/followers","following_url":"https://api.github.com/users/ne0nx/following{/other_user}","gists_url":"https://api.github.com/users/ne0nx/gists{/gist_id}","starred_url":"https://api.github.com/users/ne0nx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ne0nx/subscriptions","organizations_url":"https://api.github.com/users/ne0nx/orgs","repos_url":"https://api.github.com/users/ne0nx/repos","events_url":"https://api.github.com/users/ne0nx/events{/privacy}","received_events_url":"https://api.github.com/users/ne0nx/received_events","type":"User","site_admin":false},"repo":{"id":71086989,"name":"Library-Ruby","full_name":"ne0nx/Library-Ruby","owner":{"login":"ne0nx","id":4031133,"avatar_url":"https://avatars.githubusercontent.com/u/4031133?v=3","gravatar_id":"","url":"https://api.github.com/users/ne0nx","html_url":"https://github.com/ne0nx","followers_url":"https://api.github.com/users/ne0nx/followers","following_url":"https://api.github.com/users/ne0nx/following{/other_user}","gists_url":"https://api.github.com/users/ne0nx/gists{/gist_id}","starred_url":"https://api.github.com/users/ne0nx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ne0nx/subscriptions","organizations_url":"https://api.github.com/users/ne0nx/orgs","repos_url":"https://api.github.com/users/ne0nx/repos","events_url":"https://api.github.com/users/ne0nx/events{/privacy}","received_events_url":"https://api.github.com/users/ne0nx/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ne0nx/Library-Ruby","description":null,"fork":false,"url":"https://api.github.com/repos/ne0nx/Library-Ruby","forks_url":"https://api.github.com/repos/ne0nx/Library-Ruby/forks","keys_url":"https://api.github.com/repos/ne0nx/Library-Ruby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ne0nx/Library-Ruby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ne0nx/Library-Ruby/teams","hooks_url":"https://api.github.com/repos/ne0nx/Library-Ruby/hooks","issue_events_url":"https://api.github.com/repos/ne0nx/Library-Ruby/issues/events{/number}","events_url":"https://api.github.com/repos/ne0nx/Library-Ruby/events","assignees_url":"https://api.github.com/repos/ne0nx/Library-Ruby/assignees{/user}","branches_url":"https://api.github.com/repos/ne0nx/Library-Ruby/branches{/branch}","tags_url":"https://api.github.com/repos/ne0nx/Library-Ruby/tags","blobs_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/refs{/sha}","trees_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ne0nx/Library-Ruby/statuses/{sha}","languages_url":"https://api.github.com/repos/ne0nx/Library-Ruby/languages","stargazers_url":"https://api.github.com/repos/ne0nx/Library-Ruby/stargazers","contributors_url":"https://api.github.com/repos/ne0nx/Library-Ruby/contributors","subscribers_url":"https://api.github.com/repos/ne0nx/Library-Ruby/subscribers","subscription_url":"https://api.github.com/repos/ne0nx/Library-Ruby/subscription","commits_url":"https://api.github.com/repos/ne0nx/Library-Ruby/commits{/sha}","git_commits_url":"https://api.github.com/repos/ne0nx/Library-Ruby/git/commits{/sha}","comments_url":"https://api.github.com/repos/ne0nx/Library-Ruby/comments{/number}","issue_comment_url":"https://api.github.com/repos/ne0nx/Library-Ruby/issues/comments{/number}","contents_url":"https://api.github.com/repos/ne0nx/Library-Ruby/contents/{+path}","compare_url":"https://api.github.com/repos/ne0nx/Library-Ruby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ne0nx/Library-Ruby/merges","archive_url":"https://api.github.com/repos/ne0nx/Library-Ruby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ne0nx/Library-Ruby/downloads","issues_url":"https://api.github.com/repos/ne0nx/Library-Ruby/issues{/number}","pulls_url":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls{/number}","milestones_url":"https://api.github.com/repos/ne0nx/Library-Ruby/milestones{/number}","notifications_url":"https://api.github.com/repos/ne0nx/Library-Ruby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ne0nx/Library-Ruby/labels{/name}","releases_url":"https://api.github.com/repos/ne0nx/Library-Ruby/releases{/id}","deployments_url":"https://api.github.com/repos/ne0nx/Library-Ruby/deployments","created_at":"2016-10-17T00:47:11Z","updated_at":"2016-10-17T00:47:11Z","pushed_at":"2016-11-28T16:36:11Z","git_url":"git://github.com/ne0nx/Library-Ruby.git","ssh_url":"git@github.com:ne0nx/Library-Ruby.git","clone_url":"https://github.com/ne0nx/Library-Ruby.git","svn_url":"https://github.com/ne0nx/Library-Ruby","homepage":null,"size":18,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/2"},"html":{"href":"https://github.com/ne0nx/Library-Ruby/pull/2"},"issue":{"href":"https://api.github.com/repos/ne0nx/Library-Ruby/issues/2"},"comments":{"href":"https://api.github.com/repos/ne0nx/Library-Ruby/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ne0nx/Library-Ruby/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/ne0nx/Library-Ruby/statuses/ea055e6ad7094f7e47844eac9180f41ebf7d8e6d"}}}}
{"actor":{"display_login":"ne0nx"}}