Class: WMATA_Alerts
Instance Method Summary
collapse
Methods inherited from Geeklet
#show_help
#add_overrides, #command_parser, #configurableValue, #configurations, included, #isHelp?, #registerConfiguration
Instance Method Details
#description ⇒ Object
17
18
19
|
# File 'lib/WMATA_Alerts/wmata_alerts.rb', line 17
def description
"Returns WMATA feed information for metro lines."
end
|
#name ⇒ Object
13
14
15
|
# File 'lib/WMATA_Alerts/wmata_alerts.rb', line 13
def name
"WMATA_Alerts"
end
|
#run(params) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/WMATA_Alerts/wmata_alerts.rb', line 29
def run(params)
super(:WMATA_Alerts, params)
= ""
open(configurableValue(:WMATA_Alerts, :URL)) do |f|
= f.read
end
= RSS::Parser.parse(, false)
item_hash = {}
.items.each do |item|
item_hash[item.pubDate] = item unless item.pubDate < Chronic.parse(configurableValue(:WMATA_Alerts, :history))
end
if item_hash.empty?
puts "No data from WMATA feed."
else
coder = HTMLEntities.new
item_hash.keys.sort.reverse.each do |key|
item = item_hash[key]
title = "#{item.pubDate.strftime('%x')} - #{item.title}"
puts title
puts ("-" * title.length)
message = coder.decode(item.description)
message = translate(message)
subject, *body = message.split(".")
width = configurableValue(:WMATA_Alerts, :width)
puts Utility.wrap_text(subject + "...", width)
body.each do |sentence|
puts Utility.wrap_text(sentence + ".", width, 3, :all)
end
puts
end
end
end
|
#translate(message) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/WMATA_Alerts/wmata_alerts.rb', line 21
def translate(message)
[
["p.m.", "pm"],
["a.m.", "am"]
].each { |r| message.gsub!(r[0], r[1]) }
message
end
|