{"action":"created","comment":{"url":"https://api.github.com/repos/jbrr/rales-engine/pulls/comments/43975218","id":43975218,"diff_hunk":"@@ -1,4 +1,27 @@\n class Merchant < ActiveRecord::Base\n   has_many :invoices\n   has_many :items\n+  has_many :invoice_items, through: :invoices\n+\n+  def self.revenue(params)\n+    merchant = Merchant.find(params[:id])\n+    if params[:date]\n+      rev = merchant.invoices.where(created_at: params[:date]).successful_transactions.joins(:invoice_items).sum(\"unit_price * quantity\")\n+    else\n+      rev = merchant.invoices.successful_transactions.joins(:invoice_items).sum(\"unit_price * quantity\")\n+    end\n+    revenue_format = (rev.to_f / 100).to_s\n+    { revenue: revenue_format }\n+  end\n+\n+  def self.favorite_customer(id)\n+    merchant = Merchant.find(id)\n+    customer_id = merchant.invoices.successful_transactions.group_by(&:customer_id).max_by { |k, v| v.count }.flatten.first\n+    Customer.find(customer_id)\n+  end\n+\n+  def self.pending_customers(id)\n+    merchant = Merchant.find(id)\n+    merchant.invoices.pending_transactions.map{ |invoice| invoice.customer }.uniq","path":"app/models/merchant.rb","position":25,"original_position":25,"commit_id":"0e57413c5c4a817dcb6e0216d7c17d49bd4c5c70","original_commit_id":"0e57413c5c4a817dcb6e0216d7c17d49bd4c5c70","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Line is too long. [81/80]<br>Space missing to the left of {.<br>Pass `&:customer` as an argument to `map` instead of a block.","created_at":"2015-11-05T04:22:42Z","updated_at":"2015-11-05T04:22:42Z","html_url":"https://github.com/jbrr/rales-engine/pull/4#discussion_r43975218","pull_request_url":"https://api.github.com/repos/jbrr/rales-engine/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/jbrr/rales-engine/pulls/comments/43975218"},"html":{"href":"https://github.com/jbrr/rales-engine/pull/4#discussion_r43975218"},"pull_request":{"href":"https://api.github.com/repos/jbrr/rales-engine/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/jbrr/rales-engine/pulls/4","id":49781053,"html_url":"https://github.com/jbrr/rales-engine/pull/4","diff_url":"https://github.com/jbrr/rales-engine/pull/4.diff","patch_url":"https://github.com/jbrr/rales-engine/pull/4.patch","issue_url":"https://api.github.com/repos/jbrr/rales-engine/issues/4","number":4,"state":"open","locked":false,"title":"Bi","user":{"login":"jbrr","id":3893765,"avatar_url":"https://avatars.githubusercontent.com/u/3893765?v=3","gravatar_id":"","url":"https://api.github.com/users/jbrr","html_url":"https://github.com/jbrr","followers_url":"https://api.github.com/users/jbrr/followers","following_url":"https://api.github.com/users/jbrr/following{/other_user}","gists_url":"https://api.github.com/users/jbrr/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrr/subscriptions","organizations_url":"https://api.github.com/users/jbrr/orgs","repos_url":"https://api.github.com/users/jbrr/repos","events_url":"https://api.github.com/users/jbrr/events{/privacy}","received_events_url":"https://api.github.com/users/jbrr/received_events","type":"User","site_admin":false},"body":"Some business intelligence done. This was a terrible week to get sick, I can't concentrate at all and I think this is as far as I'll make it before the evaluation. 96% test coverage, but could use more model testing. 5 failing tests on the spec harness. This could definitely use some refactoring. This isn't my best work, but I gave it my all considering the time constraint and this damn cold.","created_at":"2015-11-05T04:22:37Z","updated_at":"2015-11-05T04:22:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe62d3477174d742a1811d4827906d02ebb827ba","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jbrr/rales-engine/pulls/4/commits","review_comments_url":"https://api.github.com/repos/jbrr/rales-engine/pulls/4/comments","review_comment_url":"https://api.github.com/repos/jbrr/rales-engine/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jbrr/rales-engine/issues/4/comments","statuses_url":"https://api.github.com/repos/jbrr/rales-engine/statuses/0e57413c5c4a817dcb6e0216d7c17d49bd4c5c70","head":{"label":"jbrr:bi","ref":"bi","sha":"0e57413c5c4a817dcb6e0216d7c17d49bd4c5c70","user":{"login":"jbrr","id":3893765,"avatar_url":"https://avatars.githubusercontent.com/u/3893765?v=3","gravatar_id":"","url":"https://api.github.com/users/jbrr","html_url":"https://github.com/jbrr","followers_url":"https://api.github.com/users/jbrr/followers","following_url":"https://api.github.com/users/jbrr/following{/other_user}","gists_url":"https://api.github.com/users/jbrr/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrr/subscriptions","organizations_url":"https://api.github.com/users/jbrr/orgs","repos_url":"https://api.github.com/users/jbrr/repos","events_url":"https://api.github.com/users/jbrr/events{/privacy}","received_events_url":"https://api.github.com/users/jbrr/received_events","type":"User","site_admin":false},"repo":{"id":45425637,"name":"rales-engine","full_name":"jbrr/rales-engine","owner":{"login":"jbrr","id":3893765,"avatar_url":"https://avatars.githubusercontent.com/u/3893765?v=3","gravatar_id":"","url":"https://api.github.com/users/jbrr","html_url":"https://github.com/jbrr","followers_url":"https://api.github.com/users/jbrr/followers","following_url":"https://api.github.com/users/jbrr/following{/other_user}","gists_url":"https://api.github.com/users/jbrr/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrr/subscriptions","organizations_url":"https://api.github.com/users/jbrr/orgs","repos_url":"https://api.github.com/users/jbrr/repos","events_url":"https://api.github.com/users/jbrr/events{/privacy}","received_events_url":"https://api.github.com/users/jbrr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jbrr/rales-engine","description":"","fork":false,"url":"https://api.github.com/repos/jbrr/rales-engine","forks_url":"https://api.github.com/repos/jbrr/rales-engine/forks","keys_url":"https://api.github.com/repos/jbrr/rales-engine/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jbrr/rales-engine/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jbrr/rales-engine/teams","hooks_url":"https://api.github.com/repos/jbrr/rales-engine/hooks","issue_events_url":"https://api.github.com/repos/jbrr/rales-engine/issues/events{/number}","events_url":"https://api.github.com/repos/jbrr/rales-engine/events","assignees_url":"https://api.github.com/repos/jbrr/rales-engine/assignees{/user}","branches_url":"https://api.github.com/repos/jbrr/rales-engine/branches{/branch}","tags_url":"https://api.github.com/repos/jbrr/rales-engine/tags","blobs_url":"https://api.github.com/repos/jbrr/rales-engine/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jbrr/rales-engine/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jbrr/rales-engine/git/refs{/sha}","trees_url":"https://api.github.com/repos/jbrr/rales-engine/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jbrr/rales-engine/statuses/{sha}","languages_url":"https://api.github.com/repos/jbrr/rales-engine/languages","stargazers_url":"https://api.github.com/repos/jbrr/rales-engine/stargazers","contributors_url":"https://api.github.com/repos/jbrr/rales-engine/contributors","subscribers_url":"https://api.github.com/repos/jbrr/rales-engine/subscribers","subscription_url":"https://api.github.com/repos/jbrr/rales-engine/subscription","commits_url":"https://api.github.com/repos/jbrr/rales-engine/commits{/sha}","git_commits_url":"https://api.github.com/repos/jbrr/rales-engine/git/commits{/sha}","comments_url":"https://api.github.com/repos/jbrr/rales-engine/comments{/number}","issue_comment_url":"https://api.github.com/repos/jbrr/rales-engine/issues/comments{/number}","contents_url":"https://api.github.com/repos/jbrr/rales-engine/contents/{+path}","compare_url":"https://api.github.com/repos/jbrr/rales-engine/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jbrr/rales-engine/merges","archive_url":"https://api.github.com/repos/jbrr/rales-engine/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jbrr/rales-engine/downloads","issues_url":"https://api.github.com/repos/jbrr/rales-engine/issues{/number}","pulls_url":"https://api.github.com/repos/jbrr/rales-engine/pulls{/number}","milestones_url":"https://api.github.com/repos/jbrr/rales-engine/milestones{/number}","notifications_url":"https://api.github.com/repos/jbrr/rales-engine/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jbrr/rales-engine/labels{/name}","releases_url":"https://api.github.com/repos/jbrr/rales-engine/releases{/id}","created_at":"2015-11-02T22:14:51Z","updated_at":"2015-11-02T22:15:12Z","pushed_at":"2015-11-05T04:22:37Z","git_url":"git://github.com/jbrr/rales-engine.git","ssh_url":"git@github.com:jbrr/rales-engine.git","clone_url":"https://github.com/jbrr/rales-engine.git","svn_url":"https://github.com/jbrr/rales-engine","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"jbrr:master","ref":"master","sha":"dfcf3769e98b4550628827f9c2fef67b0ea39ae1","user":{"login":"jbrr","id":3893765,"avatar_url":"https://avatars.githubusercontent.com/u/3893765?v=3","gravatar_id":"","url":"https://api.github.com/users/jbrr","html_url":"https://github.com/jbrr","followers_url":"https://api.github.com/users/jbrr/followers","following_url":"https://api.github.com/users/jbrr/following{/other_user}","gists_url":"https://api.github.com/users/jbrr/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrr/subscriptions","organizations_url":"https://api.github.com/users/jbrr/orgs","repos_url":"https://api.github.com/users/jbrr/repos","events_url":"https://api.github.com/users/jbrr/events{/privacy}","received_events_url":"https://api.github.com/users/jbrr/received_events","type":"User","site_admin":false},"repo":{"id":45425637,"name":"rales-engine","full_name":"jbrr/rales-engine","owner":{"login":"jbrr","id":3893765,"avatar_url":"https://avatars.githubusercontent.com/u/3893765?v=3","gravatar_id":"","url":"https://api.github.com/users/jbrr","html_url":"https://github.com/jbrr","followers_url":"https://api.github.com/users/jbrr/followers","following_url":"https://api.github.com/users/jbrr/following{/other_user}","gists_url":"https://api.github.com/users/jbrr/gists{/gist_id}","starred_url":"https://api.github.com/users/jbrr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbrr/subscriptions","organizations_url":"https://api.github.com/users/jbrr/orgs","repos_url":"https://api.github.com/users/jbrr/repos","events_url":"https://api.github.com/users/jbrr/events{/privacy}","received_events_url":"https://api.github.com/users/jbrr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jbrr/rales-engine","description":"","fork":false,"url":"https://api.github.com/repos/jbrr/rales-engine","forks_url":"https://api.github.com/repos/jbrr/rales-engine/forks","keys_url":"https://api.github.com/repos/jbrr/rales-engine/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jbrr/rales-engine/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jbrr/rales-engine/teams","hooks_url":"https://api.github.com/repos/jbrr/rales-engine/hooks","issue_events_url":"https://api.github.com/repos/jbrr/rales-engine/issues/events{/number}","events_url":"https://api.github.com/repos/jbrr/rales-engine/events","assignees_url":"https://api.github.com/repos/jbrr/rales-engine/assignees{/user}","branches_url":"https://api.github.com/repos/jbrr/rales-engine/branches{/branch}","tags_url":"https://api.github.com/repos/jbrr/rales-engine/tags","blobs_url":"https://api.github.com/repos/jbrr/rales-engine/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jbrr/rales-engine/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jbrr/rales-engine/git/refs{/sha}","trees_url":"https://api.github.com/repos/jbrr/rales-engine/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jbrr/rales-engine/statuses/{sha}","languages_url":"https://api.github.com/repos/jbrr/rales-engine/languages","stargazers_url":"https://api.github.com/repos/jbrr/rales-engine/stargazers","contributors_url":"https://api.github.com/repos/jbrr/rales-engine/contributors","subscribers_url":"https://api.github.com/repos/jbrr/rales-engine/subscribers","subscription_url":"https://api.github.com/repos/jbrr/rales-engine/subscription","commits_url":"https://api.github.com/repos/jbrr/rales-engine/commits{/sha}","git_commits_url":"https://api.github.com/repos/jbrr/rales-engine/git/commits{/sha}","comments_url":"https://api.github.com/repos/jbrr/rales-engine/comments{/number}","issue_comment_url":"https://api.github.com/repos/jbrr/rales-engine/issues/comments{/number}","contents_url":"https://api.github.com/repos/jbrr/rales-engine/contents/{+path}","compare_url":"https://api.github.com/repos/jbrr/rales-engine/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jbrr/rales-engine/merges","archive_url":"https://api.github.com/repos/jbrr/rales-engine/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jbrr/rales-engine/downloads","issues_url":"https://api.github.com/repos/jbrr/rales-engine/issues{/number}","pulls_url":"https://api.github.com/repos/jbrr/rales-engine/pulls{/number}","milestones_url":"https://api.github.com/repos/jbrr/rales-engine/milestones{/number}","notifications_url":"https://api.github.com/repos/jbrr/rales-engine/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jbrr/rales-engine/labels{/name}","releases_url":"https://api.github.com/repos/jbrr/rales-engine/releases{/id}","created_at":"2015-11-02T22:14:51Z","updated_at":"2015-11-02T22:15:12Z","pushed_at":"2015-11-05T04:22:37Z","git_url":"git://github.com/jbrr/rales-engine.git","ssh_url":"git@github.com:jbrr/rales-engine.git","clone_url":"https://github.com/jbrr/rales-engine.git","svn_url":"https://github.com/jbrr/rales-engine","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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/jbrr/rales-engine/pulls/4"},"html":{"href":"https://github.com/jbrr/rales-engine/pull/4"},"issue":{"href":"https://api.github.com/repos/jbrr/rales-engine/issues/4"},"comments":{"href":"https://api.github.com/repos/jbrr/rales-engine/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/jbrr/rales-engine/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/jbrr/rales-engine/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jbrr/rales-engine/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/jbrr/rales-engine/statuses/0e57413c5c4a817dcb6e0216d7c17d49bd4c5c70"}}}}