Class: DownRightNow::DownRightNow
- Inherits:
-
Object
- Object
- DownRightNow::DownRightNow
- Defined in:
- lib/downrightnow.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
The original document received and parsed.
-
#last_updated_all ⇒ Object
readonly
Overall last update as a time object.
-
#last_updates ⇒ Object
readonly
List of updates (coresponding to services) as an array of time objects.
-
#services ⇒ Object
readonly
List of services as an array of strings.
-
#statuses ⇒ Object
readonly
List of statuses (coresponding to services) as an array of strings.
Instance Method Summary collapse
- #any_outages? ⇒ Boolean
-
#initialize ⇒ DownRightNow
constructor
A new instance of DownRightNow.
-
#refresh ⇒ Object
Go fetch the status document.
-
#to_s(verbose = false) ⇒ Object
Return a human-friendly representation.
-
#to_tuple ⇒ Object
[ (services, statuses, last_updates) … ].
Constructor Details
#initialize ⇒ DownRightNow
Returns a new instance of DownRightNow.
34 35 36 |
# File 'lib/downrightnow.rb', line 34 def initialize refresh end |
Instance Attribute Details
#doc ⇒ Object (readonly)
The original document received and parsed.
20 21 22 |
# File 'lib/downrightnow.rb', line 20 def doc @doc end |
#last_updated_all ⇒ Object (readonly)
Overall last update as a time object.
32 33 34 |
# File 'lib/downrightnow.rb', line 32 def last_updated_all @last_updated_all end |
#last_updates ⇒ Object (readonly)
List of updates (coresponding to services) as an array of time objects.
29 30 31 |
# File 'lib/downrightnow.rb', line 29 def last_updates @last_updates end |
#services ⇒ Object (readonly)
List of services as an array of strings.
23 24 25 |
# File 'lib/downrightnow.rb', line 23 def services @services end |
#statuses ⇒ Object (readonly)
List of statuses (coresponding to services) as an array of strings.
26 27 28 |
# File 'lib/downrightnow.rb', line 26 def statuses @statuses end |
Instance Method Details
#any_outages? ⇒ Boolean
52 53 54 |
# File 'lib/downrightnow.rb', line 52 def any_outages? statuses.any? { |x| x != 'Up' } end |
#refresh ⇒ Object
Go fetch the status document.
39 40 41 42 43 44 45 |
# File 'lib/downrightnow.rb', line 39 def refresh @doc = Nokogiri::HTML(open('http://www.downrightnow.com')) @services = @doc.css('h2.serviceIcon a').map { |x| x.content.sub(/ status/,'') } @statuses = @doc.css('span.status').map(&:content) @last_updates = @doc.css('p.lastDisruption span.timestamp').map(&:content).map { |x| Time.parse(x) } @last_updated_all = Time.parse(@doc.css('form#autoRefreshForm p.sprite span.timestamp')[0].content) end |
#to_s(verbose = false) ⇒ Object
Return a human-friendly representation.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/downrightnow.rb', line 57 def to_s(verbose=false) alignment1 = services.map(&:length).max + 2 alignment2 = statuses.map(&:length).max + 2 result = "%*s: %*s " % [alignment1, "Service Name", -alignment2, "Status"] result += " Last Update" if verbose result += "\n" result += "-"*(alignment1+alignment2+8+(verbose ? 25:0)) + "\n" to_tuple.each { |name, status, last_update| result += "%*s: %*s " % [alignment1, name, -alignment2, status] result += " #{last_update}" if verbose result += "\n" } result += "\nOverall last update was at: #{last_updated_all}\n" result end |
#to_tuple ⇒ Object
- (services, statuses, last_updates) …
48 49 50 |
# File 'lib/downrightnow.rb', line 48 def to_tuple services.zip statuses, last_updates end |