klasowy Sensor<
#Purpose:
# => 1) Otrzymywać tekst informacja o (1) czujnik
# => 2) Parses the info, i przechować ono jako własność the obj
# przez the Struct przedmiot
# => 3) Mieć metoda the dane w .csv kartoteka
#
Struct.new (: s_id,
: s_name,
: s_dataSourceId,
: s_tmcId,
: s_type,
: s_status,
: s_speed,
: s_volume,
: s_longVolume,
: s_occupancy,
: s_lastUpdated)
def fill_struct (s_text)
@arr = Array.new (11)
@arr [(0)] = (? <=id: ").*? (? =")/
@arr [(1)] = (? <=name: ").*? (? =")/
@arr [2] = (? <=dataSourceId: ").*? (? =")/
@arr [3] = (? <=tmcID: ").*? (? =")/
@arr [4] = (? <=type: ").*? (? =")/
@arr [5] = (? <=status: ").*? (? =")/
@arr [6] = (? <=speed: ). *? (? =,)/
@arr [7] = (? <=volume: ). *? (? =,)/
@arr [8] = (? <=longVolume: ). *? (? =,)/
@arr [9] = (? <=occupancy: ). *? (? =,)/
@arr [10] = (? <=lastUpdated: nowy Data \ ("). *? (? =")/
self.s_id = s_text.scan (@arr [(0)]) [(0)]
self.s_name = s_text.scan (@arr [(1)]) [(0)]
self.s_dataSourceId = s_text.scan (@arr [2]) [(0)]
self.s_tmcId = s_text.scan (@arr [3]) [(0)]
self.s_type = s_text.scan (@arr [4]) [(0)]
self.s_status = s_text.scan (@arr [5]) [(0)]
self.s_speed = s_text.scan (@arr [6]) [(0)] .to_i
self.s_volume = s_text.scan (@arr [7]) [(0)] .to_i
self.s_longVolume = s_text.scan (@arr [8]) [(0)] .to_i
self.s_occupancy = s_text.scan (@arr [9]) [(0)] .to_i
self.s_lastUpdated = s_text.scan (@arr [10]) [(0)]
końcówka
def mysql_out (db_mysql)
końcówka
def csv_out (f_output)
self.each |i|
f_output.print i, ","
końcówka
f_output.print "\ n"
końcówka
końcówka
#Objective -
# =>
# =>
# =>
# =>
def collect_stats (s_html, s_path)
rgx_pass_1 = /id. *?}/m #1. Tworzyć RegExp jednostka
# rezultat
s_file = otwarty (s_html) .read #2. Przepustka strona internetowa w s_file zmienna
B = [] #3. Tworzyć pusty szyk
# czujnik przedmiot
s_file.scan (rgx_pass_1) .each |i| #4. Obraz cyfrowy Sznurek dla RegExp dopasowanie
# a) Przechodzić rezultat rezultat
a = Sensor.new #5. Tworzyć nowy Czujnik przedmiot
a.fill_struct (i) #6. Przywoływać the przedmiot pełnia metoda
# a) z the rezultat
b< |