Class: Watchman::Call
- Inherits:
-
Object
- Object
- Watchman::Call
- Defined in:
- lib/watchman/call.rb
Constant Summary collapse
- ResponseLevelMap =
{"A"=>"Alpha", "B"=>"Bravo", "C"=>"Charlie", "D"=>"Delta", "E"=>"Echo", "O"=>"Omega"}
Instance Method Summary collapse
- #address ⇒ Object
- #apparatus ⇒ Object
- #cross_street_1 ⇒ Object
- #cross_street_2 ⇒ Object
- #cross_streets ⇒ Object
- #dispatch_code ⇒ Object
- #fire_area ⇒ Object
- #grid ⇒ Object
- #incident_number ⇒ Object
- #incidental_notes ⇒ Object
-
#initialize(page) ⇒ Call
constructor
A new instance of Call.
- #nature ⇒ Object
- #notes ⇒ Object
- #priority ⇒ Object
- #pro_qa_notes ⇒ Object
- #raw_notes ⇒ Object
- #response_level ⇒ Object
- #spliced_notes ⇒ Object
- #time_of_alarm ⇒ Object
- #time_of_first_unit_on_scene ⇒ Object
Constructor Details
#initialize(page) ⇒ Call
Returns a new instance of Call.
3 4 5 |
# File 'lib/watchman/call.rb', line 3 def initialize(page) @page = page end |
Instance Method Details
#address ⇒ Object
17 18 19 |
# File 'lib/watchman/call.rb', line 17 def address @page.links_with(:href=>/SearchDStatsSubmit\.php\?Address/).first.text.gsub(/-BC$/,"") end |
#apparatus ⇒ Object
46 47 48 |
# File 'lib/watchman/call.rb', line 46 def apparatus xpath("/html/body/table/tr[1]/td[2]/table/tr/td[1]").map{|c| c.text.gsub("\n","").strip} end |
#cross_street_1 ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/watchman/call.rb', line 78 def cross_street_1 if xpath_text("#{main_table_path}/tr[7]/th") == "Cross1" xpath_text("#{main_table_path}/tr[7]/td") elsif xpath_text("#{main_table_path}/tr[8]/th") == "Cross1" xpath_text("#{main_table_path}/tr[8]/td") end end |
#cross_street_2 ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/watchman/call.rb', line 86 def cross_street_2 if xpath_text("#{main_table_path}/tr[8]/th") == "Cross2" xpath_text("#{main_table_path}/tr[8]/td") elsif xpath_text("#{main_table_path}/tr[9]/th") == "Cross2" xpath_text("#{main_table_path}/tr[9]/td") end end |
#cross_streets ⇒ Object
74 75 76 |
# File 'lib/watchman/call.rb', line 74 def cross_streets [cross_street_1,cross_street_2] end |
#dispatch_code ⇒ Object
98 99 100 |
# File 'lib/watchman/call.rb', line 98 def dispatch_code xpath_text("#{main_table_path}/tr[4]/td[2]") end |
#fire_area ⇒ Object
106 107 108 |
# File 'lib/watchman/call.rb', line 106 def fire_area xpath_text("#{main_table_path}/tr[6]/td") end |
#grid ⇒ Object
102 103 104 |
# File 'lib/watchman/call.rb', line 102 def grid xpath_text("#{main_table_path}/tr[5]/td[1]") end |
#incident_number ⇒ Object
21 22 23 |
# File 'lib/watchman/call.rb', line 21 def incident_number xpath("/html/body/h3[1]").text.split(":").last.strip end |
#incidental_notes ⇒ Object
54 55 56 |
# File 'lib/watchman/call.rb', line 54 def incidental_notes notes.select{|n| n[:text] =~ /^\s*\*/} end |
#nature ⇒ Object
25 26 27 |
# File 'lib/watchman/call.rb', line 25 def nature nature_cell_text.split("-").last end |
#notes ⇒ Object
11 12 13 14 15 |
# File 'lib/watchman/call.rb', line 11 def notes xpath("/html/body/table/tr[3]/table/tr/td/table/tr").map do |node| {:time=>node.children[0].text,:text=>node.children[1].text.gsub("\n","")} end end |
#priority ⇒ Object
94 95 96 |
# File 'lib/watchman/call.rb', line 94 def priority xpath_text("#{main_table_path}/tr[4]/td[1]").to_i end |
#pro_qa_notes ⇒ Object
50 51 52 |
# File 'lib/watchman/call.rb', line 50 def pro_qa_notes notes.select{|n| n[:text] =~ /^ProQA/} end |
#raw_notes ⇒ Object
7 8 9 |
# File 'lib/watchman/call.rb', line 7 def raw_notes notes.map{|n| "#{n[:time]} #{n[:text]}"}.join("|") end |
#response_level ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/watchman/call.rb', line 36 def response_level code = nature_cell_text.split("-").first if code == "IA" return "Bravo" else match = code.scan(/^\d+([A-O])/).first.first ResponseLevelMap[match] end end |
#spliced_notes ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/watchman/call.rb', line 58 def spliced_notes s_notes = {} notes.select{|n| n[:text] =~ /[\(\[]\d+-\d+[\)\]]$/}.each do |note| note_text = note[:text] note_text_arr = note_text.split(/\s/) token = note_text_arr.delete_at(note_text_arr.size - 1) final_text = note_text_arr.join(" ") if s_notes[token].nil? s_notes[token] = [{:time=>note[:time],:text=>final_text}] else s_notes[token] << {:time=>note[:time],:text=>final_text} end end s_notes end |
#time_of_alarm ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/watchman/call.rb', line 110 def time_of_alarm if xpath_text("#{main_table_path}/tr[16]/th") == "Inc Date/Time" Time.parse(xpath_text("#{main_table_path}/tr[16]/td")) elsif xpath_text("#{main_table_path}/tr[18]/th") == "Date Recd" Time.parse(xpath_text("#{main_table_path}/tr[18]/td")) end end |
#time_of_first_unit_on_scene ⇒ Object
118 119 120 |
# File 'lib/watchman/call.rb', line 118 def time_of_first_unit_on_scene Time.parse(xpath_text("#{main_table_path}/tr[17]/td")) end |