wobble 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,64 @@
1
+ require 'net/http'
2
+ require 'nokogiri'
3
+
4
+ module Wobble
5
+ class Tracker
6
+ attr_accessor :host
7
+ attr_accessor :type
8
+
9
+ def initialize(host)
10
+ @host = Nokogiri::HTML(Net::HTTP.get(URI(host)))
11
+ end
12
+
13
+ def jobs
14
+ ids.zip(priorities, users, names)
15
+ end
16
+
17
+ def find_jobs
18
+ xpath_stub = "//html/body/table[@class='datatable']"
19
+
20
+ case type
21
+ when 'running'
22
+ host.xpath("#{xpath_stub}[1]/tbody").first.search('tr')
23
+ when 'completed'
24
+ host.xpath("#{xpath_stub}[2]/tbody").first.search('tr')
25
+ when 'failed'
26
+ host.xpath("#{xpath_stub}[3]/tbody").first.search('tr')
27
+ when 'retired'
28
+ host.xpath("/html/body/table[@class='sortable'][2]/tbody").first.search('tr')
29
+ else
30
+ host.xpath("#{xpath_stub}/tbody").first.search('tr')
31
+ end
32
+ end
33
+
34
+ def find_by_id_prefix(id_prefix)
35
+ find_jobs.xpath("td[starts-with(@id, '#{id_prefix}_')]").map do |job|
36
+ job.content
37
+ end
38
+ end
39
+
40
+ def ids
41
+ find_by_id_prefix('job').map { |id| edit_id id }
42
+ end
43
+
44
+ def priorities
45
+ find_by_id_prefix 'priority'
46
+ end
47
+
48
+ def users
49
+ find_by_id_prefix 'user'
50
+ end
51
+
52
+ def names
53
+ find_by_id_prefix('name').map { |name| edit_name name }
54
+ end
55
+
56
+ def edit_id(id)
57
+ id.gsub(/job_\d+_/, '')
58
+ end
59
+
60
+ def edit_name(name)
61
+ name.gsub(/\[.*\]|\/\(\d+\/\d+\)/, '').strip[0...40]
62
+ end
63
+ end
64
+ end
@@ -1,3 +1,3 @@
1
1
  module Wobble
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wobble
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -150,6 +150,7 @@ files:
150
150
  - bin/wobble
151
151
  - lib/wobble/version.rb
152
152
  - lib/wobble.rb
153
+ - lib/wobble/tracker.rb
153
154
  - README.md
154
155
  homepage: https://github.com/2a6U37Nn/wobble
155
156
  licenses: []
@@ -170,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
171
  version: '0'
171
172
  segments:
172
173
  - 0
173
- hash: -2876792153377904379
174
+ hash: 3803746514581538851
174
175
  required_rubygems_version: !ruby/object:Gem::Requirement
175
176
  none: false
176
177
  requirements:
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  version: '0'
180
181
  segments:
181
182
  - 0
182
- hash: -2876792153377904379
183
+ hash: 3803746514581538851
183
184
  requirements: []
184
185
  rubyforge_project:
185
186
  rubygems_version: 1.8.23