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.
28 29 30 |
# File 'lib/downrightnow.rb', line 28 def initialize refresh end |
Instance Attribute Details
#doc ⇒ Object (readonly)
The original document received and parsed.
14 15 16 |
# File 'lib/downrightnow.rb', line 14 def doc @doc end |
#last_updated_all ⇒ Object (readonly)
Overall last update as a time object.
26 27 28 |
# File 'lib/downrightnow.rb', line 26 def last_updated_all @last_updated_all end |
#last_updates ⇒ Object (readonly)
List of updates (coresponding to services) as an array of time objects.
23 24 25 |
# File 'lib/downrightnow.rb', line 23 def last_updates @last_updates end |
#services ⇒ Object (readonly)
List of services as an array of strings.
17 18 19 |
# File 'lib/downrightnow.rb', line 17 def services @services end |
#statuses ⇒ Object (readonly)
List of statuses (coresponding to services) as an array of strings.
20 21 22 |
# File 'lib/downrightnow.rb', line 20 def statuses @statuses end |
Instance Method Details
#any_outages? ⇒ Boolean
46 47 48 |
# File 'lib/downrightnow.rb', line 46 def any_outages? statuses.any? { |x| x != 'Up' } end |
#refresh ⇒ Object
Go fetch the status document.
33 34 35 36 37 38 39 |
# File 'lib/downrightnow.rb', line 33 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/downrightnow.rb', line 51 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) …
42 43 44 |
# File 'lib/downrightnow.rb', line 42 def to_tuple services.zip statuses, last_updates end |