Class: Watchman::Call

Inherits:
Object
  • Object
show all
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

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

#addressObject



17
18
19
# File 'lib/watchman/call.rb', line 17

def address
  @page.links_with(:href=>/SearchDStatsSubmit\.php\?Address/).first.text.gsub(/-BC$/,"")
end

#apparatusObject



48
49
50
# File 'lib/watchman/call.rb', line 48

def apparatus
  xpath("/html/body/table/tr[1]/td[2]/table/tr/td[1]").map{|c| c.text.gsub("\n","").strip}
end

#cross_street_1Object



88
89
90
91
92
93
94
# File 'lib/watchman/call.rb', line 88

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_2Object



96
97
98
99
100
101
102
# File 'lib/watchman/call.rb', line 96

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_streetsObject



84
85
86
# File 'lib/watchman/call.rb', line 84

def cross_streets
  [cross_street_1,cross_street_2]
end

#dispatch_codeObject



108
109
110
# File 'lib/watchman/call.rb', line 108

def dispatch_code
  xpath_text("#{main_table_path}/tr[4]/td[2]")
end

#fire_areaObject



116
117
118
# File 'lib/watchman/call.rb', line 116

def fire_area
  xpath_text("#{main_table_path}/tr[6]/td")
end

#gridObject



112
113
114
# File 'lib/watchman/call.rb', line 112

def grid
  xpath_text("#{main_table_path}/tr[5]/td[1]")
end

#incident_numberObject



21
22
23
# File 'lib/watchman/call.rb', line 21

def incident_number
  xpath("/html/body/h3[1]").text.split(":").last.strip
end

#incidental_notesObject



56
57
58
# File 'lib/watchman/call.rb', line 56

def incidental_notes
  notes.select{|n| n[:text] =~ /^\s*\*/}
end

#natureObject



25
26
27
# File 'lib/watchman/call.rb', line 25

def nature
  nature_cell_text.split("-").last
end

#notesObject



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

#priorityObject



104
105
106
# File 'lib/watchman/call.rb', line 104

def priority
  xpath_text("#{main_table_path}/tr[4]/td[1]").to_i
end

#pro_qa_notesObject



52
53
54
# File 'lib/watchman/call.rb', line 52

def pro_qa_notes
  notes.select{|n| n[:text] =~ /ProQA/}
end

#raw_notesObject



7
8
9
# File 'lib/watchman/call.rb', line 7

def raw_notes
  notes.map{|n| "#{n[:time]} #{n[:text]}"}.join("|")
end

#response_levelObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/watchman/call.rb', line 36

def response_level
  code = nature_cell_text.split("-").first
  if code == "IA"
    return "Bravo"
  elsif code =~ /^\d/
    match = code.scan(/^\d+([A-O])/).first.first
    ResponseLevelMap[match]
  else
    return "N/A"
  end
end

#spliced_notesObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/watchman/call.rb', line 60

def spliced_notes
  s_notes = {}
  
  operator_notes = notes.select{|n| n[:text] =~ /[\(\[]\d+-\d+[\)\]]$/}
  splicing_notes = operator_notes + pro_qa_notes()
  splicing_notes.each do |note|
    token = "Pro QA"
    note_text = note[:text]
    if note[:text] =~ /[\(\[]\d+-\d+[\)\]]$/
      note_text_arr = note_text.split(/\s/)
      token = note_text_arr.delete_at(note_text_arr.size - 1)
      note_text = note_text_arr.join(" ")
    end
    
    if s_notes[token].nil?
      s_notes[token] = [{:time=>note[:time],:text=>note_text}]
    else
      s_notes[token] << {:time=>note[:time],:text=>note_text}
    end
  end
  
  s_notes
end

#time_of_alarmObject



120
121
122
123
124
125
126
# File 'lib/watchman/call.rb', line 120

def time_of_alarm
  if is_prior_call?
    parse_time_at "#{main_table_path}/tr[16]/td"
  elsif is_active_call?
    parse_time_at "#{main_table_path}/tr[18]/td"
  end
end

#time_of_first_unit_on_sceneObject



128
129
130
131
132
133
134
# File 'lib/watchman/call.rb', line 128

def time_of_first_unit_on_scene
  if is_prior_call?
    parse_time_at "#{main_table_path}/tr[17]/td"
  elsif is_active_call?
    parse_time_at "#{main_table_path}/tr[19]/td"
  end
end