tablegrok 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kyle Maxwell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ = tablegrok
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but
13
+ bump version in a commit by itself I can ignore when I pull)
14
+ * Send me a pull request. Bonus points for topic branches.
15
+
16
+ == Copyright
17
+
18
+ Copyright (c) 2010 Kyle Maxwell. See LICENSE for details.
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tablegrok"
8
+ gem.summary = %Q{grabs html tables as ruby}
9
+ gem.description = %Q{Look: html tables as Ruby}
10
+ gem.email = "kyle@kylemaxwell.com"
11
+ gem.homepage = "http://github.com/fizx/tablegrok"
12
+ gem.authors = ["Kyle Maxwell"]
13
+ gem.add_development_dependency "libxml-ruby"
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'spec/rake/spectask'
21
+ Spec::Rake::SpecTask.new(:spec) do |spec|
22
+ spec.libs << 'lib' << 'spec'
23
+ spec.spec_files = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+ task :spec => :check_dependencies
33
+
34
+ task :default => :spec
35
+
36
+ require 'rake/rdoctask'
37
+ Rake::RDocTask.new do |rdoc|
38
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
+
40
+ rdoc.rdoc_dir = 'rdoc'
41
+ rdoc.title = "tablegrok #{version}"
42
+ rdoc.rdoc_files.include('README*')
43
+ rdoc.rdoc_files.include('lib/**/*.rb')
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,28 @@
1
+ require "libxml"
2
+ class Tablegrok
3
+ include LibXML
4
+ include XML::HTMLParser::Options
5
+ OPTIONS = {:options => (RECOVER | NOERROR | NOWARNING | NONET)}
6
+ def initialize(options = {})
7
+ end
8
+
9
+ def parse(thing)
10
+ _parse case thing
11
+ when XML::Document: thing
12
+ when IO, File: XML::HTMLParser.io(thing, OPTIONS).parse
13
+ else; XML::HTMLParser.string(thing.to_s, OPTIONS).parse
14
+ end
15
+ end
16
+
17
+ def _parse(doc)
18
+ doc.find("//table").map do |t|
19
+ rows = t.find("tr").map{|e| e }
20
+ header = rows.shift
21
+ keys = header.find("td|th").map{|n| n.content }.map{|e| e }
22
+ rows.map do |r|
23
+ zipped = keys.zip(r.find("td|th").map{|n| n.content })
24
+ zipped.inject({}) {|m, (k, v)| m[k] = v; m }
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ [[],
2
+ [],
3
+ [],
4
+ [],
5
+ [],
6
+ [{"Status"=>"running", "System"=>"localhost"}],
7
+ [{"Status"=>"not monitored", "Process"=>"tomcat", "Uptime"=>"-"},
8
+ {"Status"=>"not monitored", "Process"=>"proxr", "Uptime"=>"-"},
9
+ {"Status"=>"not monitored", "Process"=>"nginx", "Uptime"=>"-"},
10
+ {"Status"=>"Execution failed", "Process"=>"munin", "Uptime"=>"-"},
11
+ {"Status"=>"not monitored", "Process"=>"haproxy", "Uptime"=>"-"},
12
+ {"Status"=>"running", "Process"=>"filer", "Uptime"=>"3d 0h 24m "}],
13
+ [{"Inodes usage"=>"- [-]",
14
+ "Status"=>"Does not exist",
15
+ "Device"=>"disk1",
16
+ "Space usage"=>"- [-]"},
17
+ {"Inodes usage"=>"- [-]",
18
+ "Status"=>"Does not exist",
19
+ "Device"=>"disk2",
20
+ "Space usage"=>"- [-]"},
21
+ {"Inodes usage"=>"- [-]",
22
+ "Status"=>"Does not exist",
23
+ "Device"=>"disk3",
24
+ "Space usage"=>"- [-]"}]]
@@ -0,0 +1 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <title>monit: service manager</title> <style type="text/css"> <!-- BODY { margin: 0; } BODY, P, DIV, TD, TH, TR, FORM, OL, UL, LI, INPUT, TEXTAREA, SELECT, A { font-family: Tahoma, Arial, Helvetica, sans-serif; font-size: 14px; } A:hover { text-decoration: none; } A { text-decoration: underline; } .grey { color: #666666; } --> </style><meta HTTP-EQUIV="REFRESH" CONTENT=30><meta HTTP-EQUIV="Expires" Content=0><meta HTTP-EQUIV="Pragma" CONTENT="no-cache"></head><body bgcolor="#ffffff" link="#000000" vlink="#000000" alink="#000000" text="#000000"><table cellspacing="0" cellpadding="0" width="100%" border="0"> <tr bgcolor="#6F6F6F"> <td valign="bottom"><img src="_pixel" width="1" height="1" alt=""></td> </tr></table><table cellspacing="0" cellpadding="10" width="100%" border="0"> <tr bgcolor="#DDDDDD"> <td align="left" valign="top" width="221" bgcolor="#DDDDDD"> </a><font color="#000000"><a href="http://www.tildeslash.com"><small><a href='.'>Home</a>&gt; <a href=''></a></small></a></font> </td> <td align="left" valign="top" width="918" bgcolor="#DDDDDD"> <p align="right"> <small><a href='_about'>monit 4.10.1</a></small> </td> </tr></table><table cellspacing="0" cellpadding="0" width="100%" border="0"> <tr bgcolor="#6F6F6F"> <td><img src="_pixel" width="1" height="1" alt=""></td> </tr></table><center><table cellspacing="0" cellpadding="5" width="100%" border="0"> <tr bgcolor="#BBDDFF"> <td colspan=2 valign="top" align="left" bgcolor="#EFF7FF" width="100%"> <br><h2 align="center">Monit Service Manager</h2> <p align="center">Monit is <a href='_runtime'>running</a> on kyles-macbook.local with <i>uptime, 19h&nbsp;13m&nbsp;</i> and monitoring:</p><br> </td> </tr></table><table cellspacing="0" cellpadding="0" width="100%" border="0"> <tr valign="middle" bgcolor="#6F6F6F"> <td><img src="_pixel" width="1" height="1" alt=""></td> </tr></table><br><p>&nbsp;</p><table cellspacing=0 cellpadding=3 border=0 width="90%"><tr><td width="20%"><h3><b>System</b></h3></td><td align="left"><h3><b>Status</b></h3></td></tr><tr bgcolor="#EFEFEF"><td align="left"><a href='localhost'>localhost</a></td><td align="left"><font color='#00ff00'>running</font></td></tr></table><br><p>&nbsp;</p><table cellspacing=0 cellpadding=3 border=0 width="90%"><tr><td width="20%"><h3><b>Process</b></h3></td><td align="left"><h3><b>Status</b></h3></td><td align="right"><h3><b>Uptime</b></h3></td></tr><tr bgcolor="#EFEFEF"><td width="20%"><a href='tomcat'>tomcat</a></td><td align="left"><font color='#ff8800'>not monitored</font></td><td align="right">-</td></tr><tr ><td width="20%"><a href='proxr'>proxr</a></td><td align="left"><font color='#ff8800'>not monitored</font></td><td align="right">-</td></tr><tr bgcolor="#EFEFEF"><td width="20%"><a href='nginx'>nginx</a></td><td align="left"><font color='#ff8800'>not monitored</font></td><td align="right">-</td></tr><tr ><td width="20%"><a href='munin'>munin</a></td><td align="left"><font color='#ff0000'>Execution failed</font></td><td align="right">-</td></tr><tr bgcolor="#EFEFEF"><td width="20%"><a href='haproxy'>haproxy</a></td><td align="left"><font color='#ff8800'>not monitored</font></td><td align="right">-</td></tr><tr ><td width="20%"><a href='filer'>filer</a></td><td align="left"><font color='#00ff00'>running</font></td><td align="right">3d&nbsp;0h&nbsp;24m&nbsp;</td></tr></table><br><p>&nbsp;</p><table cellspacing=0 cellpadding=3 border=0 width="90%"><tr><td width="20%"><h3><b>Device</b></h3></td><td align="left"><h3><b>Status</b></h3></td><td align="right"><h3><b>Space usage</b></h3></td><td align="right"><h3><b>Inodes usage</b></h3></td></tr><tr bgcolor="#EFEFEF"><td width="20%"><a href='disk1'>disk1</a></td><td align="left"><font color='#ff0000'>Does not exist</font></td><td align="right">- [-]</td><td align="right">- [-]</td></tr><tr ><td width="20%"><a href='disk2'>disk2</a></td><td align="left"><font color='#ff0000'>Does not exist</font></td><td align="right">- [-]</td><td align="right">- [-]</td></tr><tr bgcolor="#EFEFEF"><td width="20%"><a href='disk3'>disk3</a></td><td align="left"><font color='#ff0000'>Does not exist</font></td><td align="right">- [-]</td><td align="right">- [-]</td></tr></table></center><p>&nbsp;</p><p>&nbsp;</p><p><br></p><div align="center"><font color="#666666"><small>&copy; Copyright 2000-2007 by <a class=grey href="http://www.tildeslash.com/monit/who.html">the monit project group</a>. All Rights Reserved. </small></font></div><br></body></html>
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,11 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require "rubygems"
4
+ require 'tablegrok'
5
+ require 'spec'
6
+ require 'spec/autorun'
7
+ require "pp"
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Tablegrok" do
4
+ it "should return a good parse of the table" do
5
+ expected = eval(File.read(File.dirname(__FILE__) + "/expected.rb"))
6
+ html = File.open(File.dirname(__FILE__) + "/sample.html")
7
+ Tablegrok.new.parse(html).should == expected
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tablegrok
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle Maxwell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-21 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: libxml-ruby
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: "Look: html tables as Ruby"
26
+ email: kyle@kylemaxwell.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION
41
+ - lib/tablegrok.rb
42
+ - spec/expected.rb
43
+ - spec/sample.html
44
+ - spec/spec.opts
45
+ - spec/spec_helper.rb
46
+ - spec/tablegrok_spec.rb
47
+ has_rdoc: true
48
+ homepage: http://github.com/fizx/tablegrok
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --charset=UTF-8
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project:
71
+ rubygems_version: 1.3.5
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: grabs html tables as ruby
75
+ test_files:
76
+ - spec/expected.rb
77
+ - spec/spec_helper.rb
78
+ - spec/tablegrok_spec.rb