Class: Wobble::Tracker
- Inherits:
-
Object
- Object
- Wobble::Tracker
- Defined in:
- lib/wobble/tracker.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#status ⇒ Object
Returns the value of attribute status.
-
#xpath_prefix ⇒ Object
Returns the value of attribute xpath_prefix.
Instance Method Summary collapse
- #completed_jobs ⇒ Object
- #edit_id(id) ⇒ Object
- #edit_name(name) ⇒ Object
- #edit_timestamp(id) ⇒ Object
- #failed_jobs ⇒ Object
- #find_by_column_index(index) ⇒ Object
- #find_by_table_index(table_index = nil) ⇒ Object
- #find_jobs ⇒ Object
- #ids ⇒ Object
-
#initialize(host) ⇒ Tracker
constructor
A new instance of Tracker.
- #jobs ⇒ Object
- #mapped ⇒ Object
- #names ⇒ Object
- #priorities ⇒ Object
- #reduced ⇒ Object
- #running_jobs ⇒ Object
- #timestamps ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(host) ⇒ Tracker
Returns a new instance of Tracker.
11 12 13 14 |
# File 'lib/wobble/tracker.rb', line 11 def initialize(host) @host = Nokogiri::HTML(Net::HTTP.get(URI(host))) @xpath_prefix = "//html/body/table[@class='datatable']" end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/wobble/tracker.rb', line 7 def host @host end |
#status ⇒ Object
Returns the value of attribute status.
8 9 10 |
# File 'lib/wobble/tracker.rb', line 8 def status @status end |
#xpath_prefix ⇒ Object
Returns the value of attribute xpath_prefix.
9 10 11 |
# File 'lib/wobble/tracker.rb', line 9 def xpath_prefix @xpath_prefix end |
Instance Method Details
#completed_jobs ⇒ Object
47 48 49 |
# File 'lib/wobble/tracker.rb', line 47 def completed_jobs find_by_table_index 2 end |
#edit_id(id) ⇒ Object
93 94 95 |
# File 'lib/wobble/tracker.rb', line 93 def edit_id(id) id.gsub(/job_\d+_/, '') end |
#edit_name(name) ⇒ Object
97 98 99 |
# File 'lib/wobble/tracker.rb', line 97 def edit_name(name) name.gsub(/\[.*\]|\/\(\d+\/\d+\)/, '').strip[0...40] end |
#edit_timestamp(id) ⇒ Object
87 88 89 90 91 |
# File 'lib/wobble/tracker.rb', line 87 def (id) DateTime.parse(id.gsub(/job_/, '').gsub(/_\d+/, '')) .to_time .to_s end |
#failed_jobs ⇒ Object
51 52 53 |
# File 'lib/wobble/tracker.rb', line 51 def failed_jobs find_by_table_index 3 end |
#find_by_column_index(index) ⇒ Object
55 56 57 |
# File 'lib/wobble/tracker.rb', line 55 def find_by_column_index(index) find_jobs.xpath("td[#{index}]").map { |c| c.content }.reject(&:empty?) end |
#find_by_table_index(table_index = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/wobble/tracker.rb', line 33 def find_by_table_index(table_index=nil) if table_index table = host.xpath("#{xpath_prefix}[#{table_index}]/tbody") else table = host.xpath("#{xpath_prefix}/tbody") end table.first.search('tr') end |
#find_jobs ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wobble/tracker.rb', line 20 def find_jobs case status when 'running' running_jobs when 'completed' completed_jobs when 'failed' failed_jobs else find_by_table_index end end |
#ids ⇒ Object
63 64 65 |
# File 'lib/wobble/tracker.rb', line 63 def ids find_by_column_index(1).map { |name| edit_id name } end |
#jobs ⇒ Object
16 17 18 |
# File 'lib/wobble/tracker.rb', line 16 def jobs ids.zip(, priorities, users, names, mapped, reduced) end |
#mapped ⇒ Object
79 80 81 |
# File 'lib/wobble/tracker.rb', line 79 def mapped find_by_column_index 5 end |
#names ⇒ Object
75 76 77 |
# File 'lib/wobble/tracker.rb', line 75 def names find_by_column_index(4).map { |name| edit_name name } end |
#priorities ⇒ Object
67 68 69 |
# File 'lib/wobble/tracker.rb', line 67 def priorities find_by_column_index 2 end |
#reduced ⇒ Object
83 84 85 |
# File 'lib/wobble/tracker.rb', line 83 def reduced find_by_column_index 8 end |
#running_jobs ⇒ Object
43 44 45 |
# File 'lib/wobble/tracker.rb', line 43 def running_jobs find_by_table_index 1 end |
#timestamps ⇒ Object
59 60 61 |
# File 'lib/wobble/tracker.rb', line 59 def find_by_column_index(1).map { || } end |
#users ⇒ Object
71 72 73 |
# File 'lib/wobble/tracker.rb', line 71 def users find_by_column_index 3 end |