Class: Wfstatus::Wfmessage

Inherits:
Object
  • Object
show all
Defined in:
lib/wfstatus/wfmessage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, message, url, config)
  @posted = DateTime.strptime(posted)
  @title = title
  @message = message
  @url = url
  @config = config
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/wfstatus/wfmessage.rb', line 3

def message
  @message
end

#postedObject (readonly)

Returns the value of attribute posted.



3
4
5
# File 'lib/wfstatus/wfmessage.rb', line 3

def posted
  @posted
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/wfstatus/wfmessage.rb', line 3

def title
  @title
end

#urlObject (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_strObject



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

Returns:

  • (Boolean)


21
22
23
# File 'lib/wfstatus/wfmessage.rb', line 21

def relevant?
  servers.detect { |s| @config['servers'].keys.include?(s) }
end

#server_infoObject



25
26
27
# File 'lib/wfstatus/wfmessage.rb', line 25

def server_info
 @config['servers'].values_at(*servers).compact.join(", ")
end

#serversObject



13
14
15
# File 'lib/wfstatus/wfmessage.rb', line 13

def servers
  @servers ||= find_servers(@title) | find_servers(@message)
end

#to_sObject



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