{"action":"created","comment":{"url":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/comments/29444363","id":29444363,"diff_hunk":"@@ -0,0 +1,123 @@\n+# ! MINOR BUGS: \n+# 1) :text is being deleted from the <ul> node. I know this has to do with \n+# the special gsub for <li> children but not specifically why it's happening.\n+# 2) Spacing error on some of the other :text fields. Specifically the 'outer-div'\n+\n+# Create a DOM Tree Class\n+\n+# First thing is to create the Node struct\n+Node = Struct.new(:name, :text, :classes, :id, :children, :parent)\n+\n+class DOMTree\n+\tattr_reader :file\n+\tattr_accessor :head\n+\n+\tdef initialize(file_name)\n+\t\t# gsub(/<!.*?>/, \"\") Removes <! doctype > from the document\n+\t\t# gsub(/>\\s*</,\"><\") Removes all the whitespace from between > & < characters\n+\t\t# gsub(/\\n/, \"\") Removes the newline characters from the document\n+\t\t@file = load(file_name).read.gsub(/\\n/, \"\").gsub(/>\\s*</,\"><\").gsub(/<!.*?>/, \"\")\n+\t\t@head = Node.new(\"Document\", @file)\n+\tend\n+\n+\tdef load(file_name)\n+\t\tFile.open(file_name, \"r\")\n+\tend\n+\n+\t# Recursively get the children for each node. Returns nil\n+\t# if there are no more children.\n+\tdef create_tree\n+\t\tqueue = [@head]\n+\t\twhile !queue.empty?\n+\t\t\tcurrent_node = queue.pop\n+\t\t\tif has_children?(current_node.text)\n+\t\t\t\tcurrent_node.children = []\n+\t\t\t\tcreate_children(current_node, queue)\n+\t\t\telse\n+\t\t\t\tcurrent_node.text = current_node.text.strip\n+\t\t\tend\n+\t\tend\n+\tend\n+\n+\tdef create_children(node, queue)\n+\t\twhile has_children?(node.text)\n+\t\t\tfirst_tag = get_first_tag(node.text)\n+\t\t\tchild_name = get_name(first_tag)\n+\t\t\tchild_class = (get_class(first_tag) == false ? nil :  get_class(first_tag))\n+\t\t\tchild_id = (get_id(first_tag) == false ? nil :  get_id(first_tag))\n+\t\t\tchild_text = (child_name == \"li\" ? get_inner_HTML(node.text, child_name, true) : get_inner_HTML(node.text, child_name))\n+\t\t\tchild_node = Node.new(child_name, child_text, child_class, child_id, nil, node)\n+\t\t\tnode.children << child_node\n+\t\t\tqueue.unshift(child_node)\n+\t\t\tif child_name == \"li\" # Need to make things lazy for <li>\n+\t\t\t\tnode.text = node.text.gsub(/^.*?(<#{child_name}.*?>.*?<\\/#{child_name}>)/, \"\")\n+\t\t\telse\n+\t\t\t\tnode.text = node.text.gsub(/(<#{child_name}.*?>.*<\\/#{child_name}>)/, \"\")\n+\t\t\tend\n+\t\tend\n+\tend\n+\n+\t# Return the HTML from between a pair of tags by name.\n+\tdef get_inner_HTML(input, name, lazy = false)\n+\t\tif lazy == true\n+\t\t\tmatches = input.match(/^.*?<#{name}.*?>(.*?)<\\/#{name}>/)\n+\t\telse\n+\t\t\tmatches = input.match(/<#{name}.*?>(.*)<\\/#{name}>/)\n+\t\tend\n+\t\tmatches ? matches.captures[0] : false\n+\tend\n+\n+\tdef has_children?(input)\n+\t\t# Looking for any kind of <> in the text. Remember, <...> tags might not\n+\t\t# be at the beginning.\n+\t\tmatches = input.match(/<(.*?)>/)\n+\t\t(get_first_tag(input) == false && matches.nil?) ? false : true \n+\tend\n+\n+\t# Function will take an argument and return everything between the \n+\t# first <...> tags. Otherwise returns false.\n+\tdef get_first_tag(input)\n+\t\tmatches = input.match(/<(.*?)>/)\n+\t\t# We only want to return the first thing captured by this. Otherwise\n+\t\t# return false.\n+\t\tmatches ? matches.captures[0] : false\n+\tend\n+\n+\t# Function takes an argument (which which has already been sterilized by the get_first_tag function) \n+\t# and will then return the NAME of the tag. This will be used later so that I can get the \n+\t# first and last tags of a particular group.\n+\tdef get_name(input)\n+\t\t# Regex is to match the 'name' of a certain tag. It looks for any amount of \n+\t\t# characters after the beginning and stops when it reaches a space the end of the string. \n+\t\t# This way both <html> and <p class=\"foo\"> will match \"html\" and \"p\" respectively.\n+\t\tmatches = input.match(/^(.*?)\\s|^(.*?)$/)\n+\t\t# The name could be in the first or the second match. Therefore we want to check if the first\n+\t\t# match is nil. If it is, return the second.\n+\t\tmatches.captures[0].nil? ? matches.captures[1] : matches.captures[0]\n+\tend\n+\n+\t# Function will take an argument (steralized from get_first_tag) and return\n+\t# the class of the tag if it has one. Otherwise will return false.\n+\tdef get_id(input)\n+\t\t# Trying to account for two situations. 1) Where double-quotes OR single-quotes \n+\t\t# are used. 2) Where there is a space after the ID (i.e. id =\"foo\"). Should build\n+\t\t# up other contingincies such as id = \"foo\" and id= \"foo\" but these add up quickly.\n+\t\tmatches = input.match(/id=\"(.*?)\"|id\\s=\"(.*?)\"|id='(.*?)'|id\\s='(.*?)'/)","path":"tree.rb","position":105,"original_position":105,"commit_id":"a0d59aca96dc7ed9b2061646adb4d63bfda2ab4a","original_commit_id":"a0d59aca96dc7ed9b2061646adb4d63bfda2ab4a","user":{"login":"eriktrautman","id":2977438,"avatar_url":"https://avatars.githubusercontent.com/u/2977438?v=3","gravatar_id":"","url":"https://api.github.com/users/eriktrautman","html_url":"https://github.com/eriktrautman","followers_url":"https://api.github.com/users/eriktrautman/followers","following_url":"https://api.github.com/users/eriktrautman/following{/other_user}","gists_url":"https://api.github.com/users/eriktrautman/gists{/gist_id}","starred_url":"https://api.github.com/users/eriktrautman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eriktrautman/subscriptions","organizations_url":"https://api.github.com/users/eriktrautman/orgs","repos_url":"https://api.github.com/users/eriktrautman/repos","events_url":"https://api.github.com/users/eriktrautman/events{/privacy}","received_events_url":"https://api.github.com/users/eriktrautman/received_events","type":"User","site_admin":false},"body":"That's a fun regex...\r\n","created_at":"2015-04-30T16:16:19Z","updated_at":"2015-04-30T16:16:19Z","html_url":"https://github.com/vikingeducation/project_dom_tree/pull/5#discussion_r29444363","pull_request_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/comments/29444363"},"html":{"href":"https://github.com/vikingeducation/project_dom_tree/pull/5#discussion_r29444363"},"pull_request":{"href":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/5","id":34427391,"html_url":"https://github.com/vikingeducation/project_dom_tree/pull/5","diff_url":"https://github.com/vikingeducation/project_dom_tree/pull/5.diff","patch_url":"https://github.com/vikingeducation/project_dom_tree/pull/5.patch","issue_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/issues/5","number":5,"state":"open","locked":false,"title":"DOOM Tree","user":{"login":"telwell","id":736897,"avatar_url":"https://avatars.githubusercontent.com/u/736897?v=3","gravatar_id":"","url":"https://api.github.com/users/telwell","html_url":"https://github.com/telwell","followers_url":"https://api.github.com/users/telwell/followers","following_url":"https://api.github.com/users/telwell/following{/other_user}","gists_url":"https://api.github.com/users/telwell/gists{/gist_id}","starred_url":"https://api.github.com/users/telwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telwell/subscriptions","organizations_url":"https://api.github.com/users/telwell/orgs","repos_url":"https://api.github.com/users/telwell/repos","events_url":"https://api.github.com/users/telwell/events{/privacy}","received_events_url":"https://api.github.com/users/telwell/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-30T04:19:47Z","updated_at":"2015-04-30T16:16:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1721461611ba9ab8b906391570b410a612e59453","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/5/commits","review_comments_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/5/comments","review_comment_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/comments{/number}","comments_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/issues/5/comments","statuses_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/statuses/a0d59aca96dc7ed9b2061646adb4d63bfda2ab4a","head":{"label":"telwell:master","ref":"master","sha":"a0d59aca96dc7ed9b2061646adb4d63bfda2ab4a","user":{"login":"telwell","id":736897,"avatar_url":"https://avatars.githubusercontent.com/u/736897?v=3","gravatar_id":"","url":"https://api.github.com/users/telwell","html_url":"https://github.com/telwell","followers_url":"https://api.github.com/users/telwell/followers","following_url":"https://api.github.com/users/telwell/following{/other_user}","gists_url":"https://api.github.com/users/telwell/gists{/gist_id}","starred_url":"https://api.github.com/users/telwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telwell/subscriptions","organizations_url":"https://api.github.com/users/telwell/orgs","repos_url":"https://api.github.com/users/telwell/repos","events_url":"https://api.github.com/users/telwell/events{/privacy}","received_events_url":"https://api.github.com/users/telwell/received_events","type":"User","site_admin":false},"repo":{"id":34686093,"name":"project_dom_tree","full_name":"telwell/project_dom_tree","owner":{"login":"telwell","id":736897,"avatar_url":"https://avatars.githubusercontent.com/u/736897?v=3","gravatar_id":"","url":"https://api.github.com/users/telwell","html_url":"https://github.com/telwell","followers_url":"https://api.github.com/users/telwell/followers","following_url":"https://api.github.com/users/telwell/following{/other_user}","gists_url":"https://api.github.com/users/telwell/gists{/gist_id}","starred_url":"https://api.github.com/users/telwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telwell/subscriptions","organizations_url":"https://api.github.com/users/telwell/orgs","repos_url":"https://api.github.com/users/telwell/repos","events_url":"https://api.github.com/users/telwell/events{/privacy}","received_events_url":"https://api.github.com/users/telwell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/telwell/project_dom_tree","description":"Like leaves on the wind","fork":true,"url":"https://api.github.com/repos/telwell/project_dom_tree","forks_url":"https://api.github.com/repos/telwell/project_dom_tree/forks","keys_url":"https://api.github.com/repos/telwell/project_dom_tree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telwell/project_dom_tree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telwell/project_dom_tree/teams","hooks_url":"https://api.github.com/repos/telwell/project_dom_tree/hooks","issue_events_url":"https://api.github.com/repos/telwell/project_dom_tree/issues/events{/number}","events_url":"https://api.github.com/repos/telwell/project_dom_tree/events","assignees_url":"https://api.github.com/repos/telwell/project_dom_tree/assignees{/user}","branches_url":"https://api.github.com/repos/telwell/project_dom_tree/branches{/branch}","tags_url":"https://api.github.com/repos/telwell/project_dom_tree/tags","blobs_url":"https://api.github.com/repos/telwell/project_dom_tree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telwell/project_dom_tree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telwell/project_dom_tree/git/refs{/sha}","trees_url":"https://api.github.com/repos/telwell/project_dom_tree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telwell/project_dom_tree/statuses/{sha}","languages_url":"https://api.github.com/repos/telwell/project_dom_tree/languages","stargazers_url":"https://api.github.com/repos/telwell/project_dom_tree/stargazers","contributors_url":"https://api.github.com/repos/telwell/project_dom_tree/contributors","subscribers_url":"https://api.github.com/repos/telwell/project_dom_tree/subscribers","subscription_url":"https://api.github.com/repos/telwell/project_dom_tree/subscription","commits_url":"https://api.github.com/repos/telwell/project_dom_tree/commits{/sha}","git_commits_url":"https://api.github.com/repos/telwell/project_dom_tree/git/commits{/sha}","comments_url":"https://api.github.com/repos/telwell/project_dom_tree/comments{/number}","issue_comment_url":"https://api.github.com/repos/telwell/project_dom_tree/issues/comments{/number}","contents_url":"https://api.github.com/repos/telwell/project_dom_tree/contents/{+path}","compare_url":"https://api.github.com/repos/telwell/project_dom_tree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telwell/project_dom_tree/merges","archive_url":"https://api.github.com/repos/telwell/project_dom_tree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telwell/project_dom_tree/downloads","issues_url":"https://api.github.com/repos/telwell/project_dom_tree/issues{/number}","pulls_url":"https://api.github.com/repos/telwell/project_dom_tree/pulls{/number}","milestones_url":"https://api.github.com/repos/telwell/project_dom_tree/milestones{/number}","notifications_url":"https://api.github.com/repos/telwell/project_dom_tree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telwell/project_dom_tree/labels{/name}","releases_url":"https://api.github.com/repos/telwell/project_dom_tree/releases{/id}","created_at":"2015-04-27T19:17:40Z","updated_at":"2015-04-30T04:19:03Z","pushed_at":"2015-04-30T04:19:03Z","git_url":"git://github.com/telwell/project_dom_tree.git","ssh_url":"git@github.com:telwell/project_dom_tree.git","clone_url":"https://github.com/telwell/project_dom_tree.git","svn_url":"https://github.com/telwell/project_dom_tree","homepage":null,"size":226,"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":"vikingeducation:master","ref":"master","sha":"b7fa0aff9faaa3c16a64bc6c39a31492289a9548","user":{"login":"vikingeducation","id":7231832,"avatar_url":"https://avatars.githubusercontent.com/u/7231832?v=3","gravatar_id":"","url":"https://api.github.com/users/vikingeducation","html_url":"https://github.com/vikingeducation","followers_url":"https://api.github.com/users/vikingeducation/followers","following_url":"https://api.github.com/users/vikingeducation/following{/other_user}","gists_url":"https://api.github.com/users/vikingeducation/gists{/gist_id}","starred_url":"https://api.github.com/users/vikingeducation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vikingeducation/subscriptions","organizations_url":"https://api.github.com/users/vikingeducation/orgs","repos_url":"https://api.github.com/users/vikingeducation/repos","events_url":"https://api.github.com/users/vikingeducation/events{/privacy}","received_events_url":"https://api.github.com/users/vikingeducation/received_events","type":"Organization","site_admin":false},"repo":{"id":30131474,"name":"project_dom_tree","full_name":"vikingeducation/project_dom_tree","owner":{"login":"vikingeducation","id":7231832,"avatar_url":"https://avatars.githubusercontent.com/u/7231832?v=3","gravatar_id":"","url":"https://api.github.com/users/vikingeducation","html_url":"https://github.com/vikingeducation","followers_url":"https://api.github.com/users/vikingeducation/followers","following_url":"https://api.github.com/users/vikingeducation/following{/other_user}","gists_url":"https://api.github.com/users/vikingeducation/gists{/gist_id}","starred_url":"https://api.github.com/users/vikingeducation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vikingeducation/subscriptions","organizations_url":"https://api.github.com/users/vikingeducation/orgs","repos_url":"https://api.github.com/users/vikingeducation/repos","events_url":"https://api.github.com/users/vikingeducation/events{/privacy}","received_events_url":"https://api.github.com/users/vikingeducation/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/vikingeducation/project_dom_tree","description":"Like leaves on the wind","fork":false,"url":"https://api.github.com/repos/vikingeducation/project_dom_tree","forks_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/forks","keys_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/teams","hooks_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/hooks","issue_events_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/issues/events{/number}","events_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/events","assignees_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/assignees{/user}","branches_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/branches{/branch}","tags_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/tags","blobs_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/git/refs{/sha}","trees_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/statuses/{sha}","languages_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/languages","stargazers_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/stargazers","contributors_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/contributors","subscribers_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/subscribers","subscription_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/subscription","commits_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/commits{/sha}","git_commits_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/git/commits{/sha}","comments_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/comments{/number}","issue_comment_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/issues/comments{/number}","contents_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/contents/{+path}","compare_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/merges","archive_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/downloads","issues_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/issues{/number}","pulls_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls{/number}","milestones_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/milestones{/number}","notifications_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/labels{/name}","releases_url":"https://api.github.com/repos/vikingeducation/project_dom_tree/releases{/id}","created_at":"2015-02-01T00:31:17Z","updated_at":"2015-02-01T00:31:17Z","pushed_at":"2015-04-30T04:19:49Z","git_url":"git://github.com/vikingeducation/project_dom_tree.git","ssh_url":"git@github.com:vikingeducation/project_dom_tree.git","clone_url":"https://github.com/vikingeducation/project_dom_tree.git","svn_url":"https://github.com/vikingeducation/project_dom_tree","homepage":null,"size":226,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":5,"forks":5,"open_issues":5,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/5"},"html":{"href":"https://github.com/vikingeducation/project_dom_tree/pull/5"},"issue":{"href":"https://api.github.com/repos/vikingeducation/project_dom_tree/issues/5"},"comments":{"href":"https://api.github.com/repos/vikingeducation/project_dom_tree/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/vikingeducation/project_dom_tree/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/vikingeducation/project_dom_tree/statuses/a0d59aca96dc7ed9b2061646adb4d63bfda2ab4a"}}}}