{"action":"created","comment":{"url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/comments/38869008","id":38869008,"diff_hunk":"@@ -1,3 +1,70 @@\n class Kidoikoi\n+  attr_reader :database\n \n+  def initialize(database)\n+    @database = database\n+  end\n+\n+  def split_bill_between(debtors, total_value, creditor)\n+    remove_all_duplicate_in(debtors, creditor)\n+\n+    total_people = debtors.length + 1\n+    amount = calcul_amount(total_value, total_people)\n+\n+    debtors.each do |debtor|\n+      add_amount_to_debt_between(debtor, creditor, amount)\n+    end\n+  end\n+\n+  def clear_debt_between(user1, user2)\n+    delete_debt(from: user1, to: user2)\n+    delete_debt(from: user2, to: user1)\n+  end\n+\n+  def debts_of(user)\n+    debts = database.get(user) || {}\n+    debts = eval(debts) if debts.is_a? String\n+    debts\n+  end\n+\n+  alias_method :resume_debt, :debts_of\n+\n+  private\n+\n+  def remove_all_duplicate_in(debtors, creditor)\n+    debtors.uniq!\n+    debtors.delete(creditor)\n+  end\n+\n+  def calcul_amount(total_value, total_people)\n+    (total_value / total_people).round(2)\n+  end\n+\n+  def add_amount_to_debt_between(debtor, creditor, amount)\n+    add_debt(-amount, from: debtor, to: creditor)\n+    add_debt(amount, from: creditor, to: debtor)\n+  end\n+\n+  def add_debt(amount, users={})\n+    user = users.fetch :from\n+    to_other_user = users.fetch :to\n+\n+    user_debts = debts_of(user)\n+    user_debts[to_other_user] = calcul_debt_value(user_debts[to_other_user], amount)\n+    database.set(user, user_debts)\n+  end\n+\n+  def calcul_debt_value(debt_value, amount)\n+    debt_value ||= 0\n+    debt_value += amount\n+  end\n+\n+  def delete_debt(users={})","path":"lib/kidoikoi.rb","position":62,"original_position":62,"commit_id":"60eb379a460eacdd74979be7084444c6e6275c58","original_commit_id":"60eb379a460eacdd74979be7084444c6e6275c58","user":{"login":"Skizzk","id":3338913,"avatar_url":"https://avatars.githubusercontent.com/u/3338913?v=3","gravatar_id":"","url":"https://api.github.com/users/Skizzk","html_url":"https://github.com/Skizzk","followers_url":"https://api.github.com/users/Skizzk/followers","following_url":"https://api.github.com/users/Skizzk/following{/other_user}","gists_url":"https://api.github.com/users/Skizzk/gists{/gist_id}","starred_url":"https://api.github.com/users/Skizzk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Skizzk/subscriptions","organizations_url":"https://api.github.com/users/Skizzk/orgs","repos_url":"https://api.github.com/users/Skizzk/repos","events_url":"https://api.github.com/users/Skizzk/events{/privacy}","received_events_url":"https://api.github.com/users/Skizzk/received_events","type":"User","site_admin":false},"body":"Je persiste a dire que cette syntaxe est pas géniale cf:\r\nhttps://robots.thoughtbot.com/ruby-2-keyword-arguments","created_at":"2015-09-07T15:21:58Z","updated_at":"2015-09-07T15:21:58Z","html_url":"https://github.com/blackbirdco/lita-kidoikoi/pull/1#discussion_r38869008","pull_request_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/comments/38869008"},"html":{"href":"https://github.com/blackbirdco/lita-kidoikoi/pull/1#discussion_r38869008"},"pull_request":{"href":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/1","id":43866335,"html_url":"https://github.com/blackbirdco/lita-kidoikoi/pull/1","diff_url":"https://github.com/blackbirdco/lita-kidoikoi/pull/1.diff","patch_url":"https://github.com/blackbirdco/lita-kidoikoi/pull/1.patch","issue_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/issues/1","number":1,"state":"open","locked":false,"title":"Add Kidoikoi test and implementation","user":{"login":"sal-himd","id":12863338,"avatar_url":"https://avatars.githubusercontent.com/u/12863338?v=3","gravatar_id":"","url":"https://api.github.com/users/sal-himd","html_url":"https://github.com/sal-himd","followers_url":"https://api.github.com/users/sal-himd/followers","following_url":"https://api.github.com/users/sal-himd/following{/other_user}","gists_url":"https://api.github.com/users/sal-himd/gists{/gist_id}","starred_url":"https://api.github.com/users/sal-himd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sal-himd/subscriptions","organizations_url":"https://api.github.com/users/sal-himd/orgs","repos_url":"https://api.github.com/users/sal-himd/repos","events_url":"https://api.github.com/users/sal-himd/events{/privacy}","received_events_url":"https://api.github.com/users/sal-himd/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-01T11:49:48Z","updated_at":"2015-09-07T15:21:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c70571220fe2cc489f3473a0a16c08ba7a0d341e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/1/commits","review_comments_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/1/comments","review_comment_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/issues/1/comments","statuses_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/statuses/60eb379a460eacdd74979be7084444c6e6275c58","head":{"label":"sal-himd:dev","ref":"dev","sha":"60eb379a460eacdd74979be7084444c6e6275c58","user":{"login":"sal-himd","id":12863338,"avatar_url":"https://avatars.githubusercontent.com/u/12863338?v=3","gravatar_id":"","url":"https://api.github.com/users/sal-himd","html_url":"https://github.com/sal-himd","followers_url":"https://api.github.com/users/sal-himd/followers","following_url":"https://api.github.com/users/sal-himd/following{/other_user}","gists_url":"https://api.github.com/users/sal-himd/gists{/gist_id}","starred_url":"https://api.github.com/users/sal-himd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sal-himd/subscriptions","organizations_url":"https://api.github.com/users/sal-himd/orgs","repos_url":"https://api.github.com/users/sal-himd/repos","events_url":"https://api.github.com/users/sal-himd/events{/privacy}","received_events_url":"https://api.github.com/users/sal-himd/received_events","type":"User","site_admin":false},"repo":{"id":41734666,"name":"lita-kidoikoi","full_name":"sal-himd/lita-kidoikoi","owner":{"login":"sal-himd","id":12863338,"avatar_url":"https://avatars.githubusercontent.com/u/12863338?v=3","gravatar_id":"","url":"https://api.github.com/users/sal-himd","html_url":"https://github.com/sal-himd","followers_url":"https://api.github.com/users/sal-himd/followers","following_url":"https://api.github.com/users/sal-himd/following{/other_user}","gists_url":"https://api.github.com/users/sal-himd/gists{/gist_id}","starred_url":"https://api.github.com/users/sal-himd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sal-himd/subscriptions","organizations_url":"https://api.github.com/users/sal-himd/orgs","repos_url":"https://api.github.com/users/sal-himd/repos","events_url":"https://api.github.com/users/sal-himd/events{/privacy}","received_events_url":"https://api.github.com/users/sal-himd/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sal-himd/lita-kidoikoi","description":"Lita plugin for splitting bills between coworkers","fork":true,"url":"https://api.github.com/repos/sal-himd/lita-kidoikoi","forks_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/forks","keys_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/teams","hooks_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/hooks","issue_events_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/issues/events{/number}","events_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/events","assignees_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/assignees{/user}","branches_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/branches{/branch}","tags_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/tags","blobs_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/git/refs{/sha}","trees_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/statuses/{sha}","languages_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/languages","stargazers_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/stargazers","contributors_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/contributors","subscribers_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/subscribers","subscription_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/subscription","commits_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/commits{/sha}","git_commits_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/git/commits{/sha}","comments_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/comments{/number}","issue_comment_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/issues/comments{/number}","contents_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/contents/{+path}","compare_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/merges","archive_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/downloads","issues_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/issues{/number}","pulls_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/pulls{/number}","milestones_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/milestones{/number}","notifications_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/labels{/name}","releases_url":"https://api.github.com/repos/sal-himd/lita-kidoikoi/releases{/id}","created_at":"2015-09-01T11:30:32Z","updated_at":"2015-09-01T11:30:32Z","pushed_at":"2015-09-07T14:01:58Z","git_url":"git://github.com/sal-himd/lita-kidoikoi.git","ssh_url":"git@github.com:sal-himd/lita-kidoikoi.git","clone_url":"https://github.com/sal-himd/lita-kidoikoi.git","svn_url":"https://github.com/sal-himd/lita-kidoikoi","homepage":null,"size":90,"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":"blackbirdco:master","ref":"master","sha":"efb52344db9f2f95332a9eab282ced36ea534b85","user":{"login":"blackbirdco","id":1948909,"avatar_url":"https://avatars.githubusercontent.com/u/1948909?v=3","gravatar_id":"","url":"https://api.github.com/users/blackbirdco","html_url":"https://github.com/blackbirdco","followers_url":"https://api.github.com/users/blackbirdco/followers","following_url":"https://api.github.com/users/blackbirdco/following{/other_user}","gists_url":"https://api.github.com/users/blackbirdco/gists{/gist_id}","starred_url":"https://api.github.com/users/blackbirdco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blackbirdco/subscriptions","organizations_url":"https://api.github.com/users/blackbirdco/orgs","repos_url":"https://api.github.com/users/blackbirdco/repos","events_url":"https://api.github.com/users/blackbirdco/events{/privacy}","received_events_url":"https://api.github.com/users/blackbirdco/received_events","type":"Organization","site_admin":false},"repo":{"id":41487348,"name":"lita-kidoikoi","full_name":"blackbirdco/lita-kidoikoi","owner":{"login":"blackbirdco","id":1948909,"avatar_url":"https://avatars.githubusercontent.com/u/1948909?v=3","gravatar_id":"","url":"https://api.github.com/users/blackbirdco","html_url":"https://github.com/blackbirdco","followers_url":"https://api.github.com/users/blackbirdco/followers","following_url":"https://api.github.com/users/blackbirdco/following{/other_user}","gists_url":"https://api.github.com/users/blackbirdco/gists{/gist_id}","starred_url":"https://api.github.com/users/blackbirdco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/blackbirdco/subscriptions","organizations_url":"https://api.github.com/users/blackbirdco/orgs","repos_url":"https://api.github.com/users/blackbirdco/repos","events_url":"https://api.github.com/users/blackbirdco/events{/privacy}","received_events_url":"https://api.github.com/users/blackbirdco/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/blackbirdco/lita-kidoikoi","description":"Lita plugin for splitting bills between coworkers","fork":false,"url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi","forks_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/forks","keys_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/teams","hooks_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/hooks","issue_events_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/issues/events{/number}","events_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/events","assignees_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/assignees{/user}","branches_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/branches{/branch}","tags_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/tags","blobs_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/git/refs{/sha}","trees_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/statuses/{sha}","languages_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/languages","stargazers_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/stargazers","contributors_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/contributors","subscribers_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/subscribers","subscription_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/subscription","commits_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/commits{/sha}","git_commits_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/git/commits{/sha}","comments_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/comments{/number}","issue_comment_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/issues/comments{/number}","contents_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/contents/{+path}","compare_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/merges","archive_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/downloads","issues_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/issues{/number}","pulls_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls{/number}","milestones_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/milestones{/number}","notifications_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/labels{/name}","releases_url":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/releases{/id}","created_at":"2015-08-27T13:11:42Z","updated_at":"2015-08-27T13:11:53Z","pushed_at":"2015-09-07T14:01:58Z","git_url":"git://github.com/blackbirdco/lita-kidoikoi.git","ssh_url":"git@github.com:blackbirdco/lita-kidoikoi.git","clone_url":"https://github.com/blackbirdco/lita-kidoikoi.git","svn_url":"https://github.com/blackbirdco/lita-kidoikoi","homepage":null,"size":231,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":1,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/1"},"html":{"href":"https://github.com/blackbirdco/lita-kidoikoi/pull/1"},"issue":{"href":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/issues/1"},"comments":{"href":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/blackbirdco/lita-kidoikoi/statuses/60eb379a460eacdd74979be7084444c6e6275c58"}}}}