{"action":"created","comment":{"url":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/comments/37320697","id":37320697,"diff_hunk":"@@ -0,0 +1,82 @@\n+require 'csv'\n+require 'json'\n+require_relative 'dinosaur'\n+\n+class Dinodex\n+  attr_reader :db\n+\n+  def each(&block)\n+    to_a.each(&block)\n+  end\n+\n+  def filters\n+    @filter ||= []\n+  end\n+\n+  def filter(args)\n+    args[:op] ||= \"==\"\n+    args[:negate] ||= false\n+    filters.push(args)\n+    self\n+  end\n+\n+  def import(filename)\n+    db.concat(parse_csv(filename))\n+  end\n+\n+  def initialize\n+    @db = []\n+  end\n+\n+  def match_dino(dino)\n+    match = 1\n+\n+    filters.each do |filter|\n+      key = filter.first.first\n+      value = dino.method(key).call\n+\n+      match = test_match(match, value, filter)\n+    end\n+\n+    match == 1\n+  end\n+\n+  def parse_csv(filename)\n+    csv = CSV.new(IO.read(filename), headers: true, converters: :all)\n+\n+    csv.to_a.map { |row| Dinosaur.new(row.to_hash) }\n+  end\n+\n+  def reset_filters\n+    @filter = []\n+  end\n+\n+  def test_match(match, value, filter)\n+    op = filter[:op]\n+    negate = filter[:negate]\n+    target = filter.first.last\n+\n+    match &= 0 unless value && (\n+                 (!negate && value.method(op).call(target)) ||\n+                 (negate && !value.method(op).call(target)))\n+    match\n+  end\n+\n+  def to_a\n+    arr = db.reject do |dino|\n+      !match_dino(dino)\n+    end\n+\n+    reset_filters\n+\n+    arr","path":"dino_catalog/dinodex.rb","position":72,"original_position":72,"commit_id":"902a6a1a5dbbc07b104c9c3acc9a993ae799317b","original_commit_id":"902a6a1a5dbbc07b104c9c3acc9a993ae799317b","user":{"login":"djkotowski","id":2326295,"avatar_url":"https://avatars.githubusercontent.com/u/2326295?v=3","gravatar_id":"","url":"https://api.github.com/users/djkotowski","html_url":"https://github.com/djkotowski","followers_url":"https://api.github.com/users/djkotowski/followers","following_url":"https://api.github.com/users/djkotowski/following{/other_user}","gists_url":"https://api.github.com/users/djkotowski/gists{/gist_id}","starred_url":"https://api.github.com/users/djkotowski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/djkotowski/subscriptions","organizations_url":"https://api.github.com/users/djkotowski/orgs","repos_url":"https://api.github.com/users/djkotowski/repos","events_url":"https://api.github.com/users/djkotowski/events{/privacy}","received_events_url":"https://api.github.com/users/djkotowski/received_events","type":"User","site_admin":false},"body":"To avoid assigning `arr` just to return it after resetting the filters, try:\r\n```ruby\r\ndb.select { |dino| match_dino(dino) }.tap do\r\n  reset_filters\r\nend\r\n```","created_at":"2015-08-18T16:32:21Z","updated_at":"2015-08-18T16:32:21Z","html_url":"https://github.com/jmmastey/level_up_exercises/pull/909#discussion_r37320697","pull_request_url":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/909","_links":{"self":{"href":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/comments/37320697"},"html":{"href":"https://github.com/jmmastey/level_up_exercises/pull/909#discussion_r37320697"},"pull_request":{"href":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/909"}}},"pull_request":{"url":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/909","id":42147681,"html_url":"https://github.com/jmmastey/level_up_exercises/pull/909","diff_url":"https://github.com/jmmastey/level_up_exercises/pull/909.diff","patch_url":"https://github.com/jmmastey/level_up_exercises/pull/909.patch","issue_url":"https://api.github.com/repos/jmmastey/level_up_exercises/issues/909","number":909,"state":"open","locked":false,"title":"deja/dino_catalog","user":{"login":"DejaAugustine","id":876181,"avatar_url":"https://avatars.githubusercontent.com/u/876181?v=3","gravatar_id":"","url":"https://api.github.com/users/DejaAugustine","html_url":"https://github.com/DejaAugustine","followers_url":"https://api.github.com/users/DejaAugustine/followers","following_url":"https://api.github.com/users/DejaAugustine/following{/other_user}","gists_url":"https://api.github.com/users/DejaAugustine/gists{/gist_id}","starred_url":"https://api.github.com/users/DejaAugustine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DejaAugustine/subscriptions","organizations_url":"https://api.github.com/users/DejaAugustine/orgs","repos_url":"https://api.github.com/users/DejaAugustine/repos","events_url":"https://api.github.com/users/DejaAugustine/events{/privacy}","received_events_url":"https://api.github.com/users/DejaAugustine/received_events","type":"User","site_admin":false},"body":"I look forward to the feedback on this one.","created_at":"2015-08-11T16:15:02Z","updated_at":"2015-08-18T16:32:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"afc4411325cf8651bb5189b742ae2281d5c6489e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/909/commits","review_comments_url":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/909/comments","review_comment_url":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jmmastey/level_up_exercises/issues/909/comments","statuses_url":"https://api.github.com/repos/jmmastey/level_up_exercises/statuses/902a6a1a5dbbc07b104c9c3acc9a993ae799317b","head":{"label":"DejaAugustine:deja/dino_catalog","ref":"deja/dino_catalog","sha":"902a6a1a5dbbc07b104c9c3acc9a993ae799317b","user":{"login":"DejaAugustine","id":876181,"avatar_url":"https://avatars.githubusercontent.com/u/876181?v=3","gravatar_id":"","url":"https://api.github.com/users/DejaAugustine","html_url":"https://github.com/DejaAugustine","followers_url":"https://api.github.com/users/DejaAugustine/followers","following_url":"https://api.github.com/users/DejaAugustine/following{/other_user}","gists_url":"https://api.github.com/users/DejaAugustine/gists{/gist_id}","starred_url":"https://api.github.com/users/DejaAugustine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DejaAugustine/subscriptions","organizations_url":"https://api.github.com/users/DejaAugustine/orgs","repos_url":"https://api.github.com/users/DejaAugustine/repos","events_url":"https://api.github.com/users/DejaAugustine/events{/privacy}","received_events_url":"https://api.github.com/users/DejaAugustine/received_events","type":"User","site_admin":false},"repo":{"id":40205714,"name":"level_up_exercises","full_name":"DejaAugustine/level_up_exercises","owner":{"login":"DejaAugustine","id":876181,"avatar_url":"https://avatars.githubusercontent.com/u/876181?v=3","gravatar_id":"","url":"https://api.github.com/users/DejaAugustine","html_url":"https://github.com/DejaAugustine","followers_url":"https://api.github.com/users/DejaAugustine/followers","following_url":"https://api.github.com/users/DejaAugustine/following{/other_user}","gists_url":"https://api.github.com/users/DejaAugustine/gists{/gist_id}","starred_url":"https://api.github.com/users/DejaAugustine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DejaAugustine/subscriptions","organizations_url":"https://api.github.com/users/DejaAugustine/orgs","repos_url":"https://api.github.com/users/DejaAugustine/repos","events_url":"https://api.github.com/users/DejaAugustine/events{/privacy}","received_events_url":"https://api.github.com/users/DejaAugustine/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/DejaAugustine/level_up_exercises","description":"A series of code-related assignments to challenge starting engineers","fork":true,"url":"https://api.github.com/repos/DejaAugustine/level_up_exercises","forks_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/forks","keys_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/teams","hooks_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/hooks","issue_events_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/issues/events{/number}","events_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/events","assignees_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/assignees{/user}","branches_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/branches{/branch}","tags_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/tags","blobs_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/git/refs{/sha}","trees_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/statuses/{sha}","languages_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/languages","stargazers_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/stargazers","contributors_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/contributors","subscribers_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/subscribers","subscription_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/subscription","commits_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/commits{/sha}","git_commits_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/git/commits{/sha}","comments_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/comments{/number}","issue_comment_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/issues/comments{/number}","contents_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/contents/{+path}","compare_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/merges","archive_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/downloads","issues_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/issues{/number}","pulls_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/pulls{/number}","milestones_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/milestones{/number}","notifications_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/labels{/name}","releases_url":"https://api.github.com/repos/DejaAugustine/level_up_exercises/releases{/id}","created_at":"2015-08-04T19:48:32Z","updated_at":"2015-08-04T19:48:32Z","pushed_at":"2015-08-18T16:30:27Z","git_url":"git://github.com/DejaAugustine/level_up_exercises.git","ssh_url":"git@github.com:DejaAugustine/level_up_exercises.git","clone_url":"https://github.com/DejaAugustine/level_up_exercises.git","svn_url":"https://github.com/DejaAugustine/level_up_exercises","homepage":"http://leveluprails.herokuapp.com","size":356,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jmmastey:master","ref":"master","sha":"c90bb546a8e2398360f28a0923f4c295b9979d77","user":{"login":"jmmastey","id":302011,"avatar_url":"https://avatars.githubusercontent.com/u/302011?v=3","gravatar_id":"","url":"https://api.github.com/users/jmmastey","html_url":"https://github.com/jmmastey","followers_url":"https://api.github.com/users/jmmastey/followers","following_url":"https://api.github.com/users/jmmastey/following{/other_user}","gists_url":"https://api.github.com/users/jmmastey/gists{/gist_id}","starred_url":"https://api.github.com/users/jmmastey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmmastey/subscriptions","organizations_url":"https://api.github.com/users/jmmastey/orgs","repos_url":"https://api.github.com/users/jmmastey/repos","events_url":"https://api.github.com/users/jmmastey/events{/privacy}","received_events_url":"https://api.github.com/users/jmmastey/received_events","type":"User","site_admin":false},"repo":{"id":20705648,"name":"level_up_exercises","full_name":"jmmastey/level_up_exercises","owner":{"login":"jmmastey","id":302011,"avatar_url":"https://avatars.githubusercontent.com/u/302011?v=3","gravatar_id":"","url":"https://api.github.com/users/jmmastey","html_url":"https://github.com/jmmastey","followers_url":"https://api.github.com/users/jmmastey/followers","following_url":"https://api.github.com/users/jmmastey/following{/other_user}","gists_url":"https://api.github.com/users/jmmastey/gists{/gist_id}","starred_url":"https://api.github.com/users/jmmastey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmmastey/subscriptions","organizations_url":"https://api.github.com/users/jmmastey/orgs","repos_url":"https://api.github.com/users/jmmastey/repos","events_url":"https://api.github.com/users/jmmastey/events{/privacy}","received_events_url":"https://api.github.com/users/jmmastey/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jmmastey/level_up_exercises","description":"A series of code-related assignments to challenge starting engineers","fork":false,"url":"https://api.github.com/repos/jmmastey/level_up_exercises","forks_url":"https://api.github.com/repos/jmmastey/level_up_exercises/forks","keys_url":"https://api.github.com/repos/jmmastey/level_up_exercises/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jmmastey/level_up_exercises/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jmmastey/level_up_exercises/teams","hooks_url":"https://api.github.com/repos/jmmastey/level_up_exercises/hooks","issue_events_url":"https://api.github.com/repos/jmmastey/level_up_exercises/issues/events{/number}","events_url":"https://api.github.com/repos/jmmastey/level_up_exercises/events","assignees_url":"https://api.github.com/repos/jmmastey/level_up_exercises/assignees{/user}","branches_url":"https://api.github.com/repos/jmmastey/level_up_exercises/branches{/branch}","tags_url":"https://api.github.com/repos/jmmastey/level_up_exercises/tags","blobs_url":"https://api.github.com/repos/jmmastey/level_up_exercises/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jmmastey/level_up_exercises/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jmmastey/level_up_exercises/git/refs{/sha}","trees_url":"https://api.github.com/repos/jmmastey/level_up_exercises/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jmmastey/level_up_exercises/statuses/{sha}","languages_url":"https://api.github.com/repos/jmmastey/level_up_exercises/languages","stargazers_url":"https://api.github.com/repos/jmmastey/level_up_exercises/stargazers","contributors_url":"https://api.github.com/repos/jmmastey/level_up_exercises/contributors","subscribers_url":"https://api.github.com/repos/jmmastey/level_up_exercises/subscribers","subscription_url":"https://api.github.com/repos/jmmastey/level_up_exercises/subscription","commits_url":"https://api.github.com/repos/jmmastey/level_up_exercises/commits{/sha}","git_commits_url":"https://api.github.com/repos/jmmastey/level_up_exercises/git/commits{/sha}","comments_url":"https://api.github.com/repos/jmmastey/level_up_exercises/comments{/number}","issue_comment_url":"https://api.github.com/repos/jmmastey/level_up_exercises/issues/comments{/number}","contents_url":"https://api.github.com/repos/jmmastey/level_up_exercises/contents/{+path}","compare_url":"https://api.github.com/repos/jmmastey/level_up_exercises/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jmmastey/level_up_exercises/merges","archive_url":"https://api.github.com/repos/jmmastey/level_up_exercises/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jmmastey/level_up_exercises/downloads","issues_url":"https://api.github.com/repos/jmmastey/level_up_exercises/issues{/number}","pulls_url":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls{/number}","milestones_url":"https://api.github.com/repos/jmmastey/level_up_exercises/milestones{/number}","notifications_url":"https://api.github.com/repos/jmmastey/level_up_exercises/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jmmastey/level_up_exercises/labels{/name}","releases_url":"https://api.github.com/repos/jmmastey/level_up_exercises/releases{/id}","created_at":"2014-06-10T23:42:24Z","updated_at":"2015-07-09T21:47:15Z","pushed_at":"2015-08-18T15:28:46Z","git_url":"git://github.com/jmmastey/level_up_exercises.git","ssh_url":"git@github.com:jmmastey/level_up_exercises.git","clone_url":"https://github.com/jmmastey/level_up_exercises.git","svn_url":"https://github.com/jmmastey/level_up_exercises","homepage":"http://leveluprails.herokuapp.com","size":181124,"stargazers_count":27,"watchers_count":27,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":132,"mirror_url":null,"open_issues_count":25,"forks":132,"open_issues":25,"watchers":27,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/909"},"html":{"href":"https://github.com/jmmastey/level_up_exercises/pull/909"},"issue":{"href":"https://api.github.com/repos/jmmastey/level_up_exercises/issues/909"},"comments":{"href":"https://api.github.com/repos/jmmastey/level_up_exercises/issues/909/comments"},"review_comments":{"href":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/909/comments"},"review_comment":{"href":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jmmastey/level_up_exercises/pulls/909/commits"},"statuses":{"href":"https://api.github.com/repos/jmmastey/level_up_exercises/statuses/902a6a1a5dbbc07b104c9c3acc9a993ae799317b"}}}}