Class: OPM_Alerts

Inherits:
Geeklet show all
Defined in:
lib/OPM_Alerts/opm_alerts.rb

Instance Method Summary collapse

Methods inherited from Geeklet

#name, #show_help

Methods included from Configurable

#add_overrides, #command_parser, #configurableValue, #configurations, included, #isHelp?, #registerConfiguration

Instance Method Details

#descriptionObject



10
11
12
# File 'lib/OPM_Alerts/opm_alerts.rb', line 10

def description
  "Returns U.S. Office of Personnel Management status Alerts."
end

#run(params) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/OPM_Alerts/opm_alerts.rb', line 14

def run(params)
  super(:OPM_Alerts, params)
  
  doc = Nokogiri::HTML(open(configurableValue(:OPM_Alerts, :URL)))

  date_str = doc.css('#_ctl0__ctl0_DisplayDateSpan').text.strip
  begin
    date = Date.parse(date_str)
    date_str = date.strftime("%x")
  rescue
    date_str = Date.today.strftime("%x") if date_str.length == 0
  end

  title = doc.css('h3').text.strip
  title = "VRE Status" if title.length == 0

  status = doc.css('.statusbox').text.strip

  # Deal with the flaky case where OPM decides to
  # display an image instead of actual text content
  images = doc.xpath("//img")
  status = images[0].attributes["alt"].text.strip if ((status.length == 0) && (images.count == 1))

  status = "Not found" if status.length == 0

  # display results
  width = configurableValue(:OPM_Alerts, :width)
  puts Utility.wrap_text("#{date_str} - #{title}", width, date_str.length + 3, :outdent)
  puts "-" * width
  puts Utility.wrap_text(status, width)
end