Class: Wfstatus::Wfmessage
- Inherits:
-
Object
- Object
- Wfstatus::Wfmessage
- Defined in:
- lib/wfstatus/wfmessage.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#posted ⇒ Object
readonly
Returns the value of attribute posted.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #find_servers(str) ⇒ Object
-
#initialize(posted, title, message, url, config) ⇒ Wfmessage
constructor
A new instance of Wfmessage.
- #posted_str ⇒ Object
- #relevant? ⇒ Boolean
- #server_info ⇒ Object
- #servers ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(posted, title, message, url, config) ⇒ Wfmessage
Returns a new instance of Wfmessage.
5 6 7 8 9 10 11 |
# File 'lib/wfstatus/wfmessage.rb', line 5 def initialize(posted, title, , url, config) @posted = DateTime.strptime(posted) @title = title @message = @url = url @config = config end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
3 4 5 |
# File 'lib/wfstatus/wfmessage.rb', line 3 def @message end |
#posted ⇒ Object (readonly)
Returns the value of attribute posted.
3 4 5 |
# File 'lib/wfstatus/wfmessage.rb', line 3 def posted @posted end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/wfstatus/wfmessage.rb', line 3 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/wfstatus/wfmessage.rb', line 3 def url @url end |
Instance Method Details
#find_servers(str) ⇒ Object
17 18 19 |
# File 'lib/wfstatus/wfmessage.rb', line 17 def find_servers(str) str.to_enum(:scan, /web\d+/i).map { Regexp.last_match.to_s.downcase } end |
#posted_str ⇒ Object
33 34 35 |
# File 'lib/wfstatus/wfmessage.rb', line 33 def posted_str @posted.to_time.localtime(@config['utc_offset']).strftime("%l:%M:%S %p %A, %b %d %Y %z") end |
#relevant? ⇒ Boolean
21 22 23 |
# File 'lib/wfstatus/wfmessage.rb', line 21 def relevant? servers.detect { |s| @config['servers'].keys.include?(s) } end |
#server_info ⇒ Object
25 26 27 |
# File 'lib/wfstatus/wfmessage.rb', line 25 def server_info @config['servers'].values_at(*servers).compact.join(", ") end |
#servers ⇒ Object
13 14 15 |
# File 'lib/wfstatus/wfmessage.rb', line 13 def servers @servers ||= find_servers(@title) | find_servers(@message) end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/wfstatus/wfmessage.rb', line 29 def to_s ["SERVER INFO: #{server_info}\n" , posted_str, @title, @message, @url].join("\n") + "\n\n" end |