Class: Tide

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

Constant Summary collapse

POST_URL =
'http://www.waterlevels.gc.ca/cgi-bin/tide-shc.cgi'
TIDE_REGEX =
/#\sDate;Time;Height<br>(.*)<br><\/p><\/td>/
STATION_REGEX =
/#\sStation\s:\s(.*)\s\(\d+\).*/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Tide

Create new tide table.



12
13
14
15
16
17
# File 'lib/tide.rb', line 12

def initialize(options = {})
  options     = { :station => 610, :timezone => 'AST', :date => Time.now }.merge(options)
  @station    = options[:station]
  @timezone   = options[:timezone]
  @date       = options[:date]
end

Class Method Details

.station(sid) ⇒ Object

Shortcut for station lookup



20
21
22
# File 'lib/tide.rb', line 20

def self.station(sid)
  new(:station => sid)
end

Instance Method Details

#dataObject

Download raw data



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

def data
  @data ||= download_tide_data
end

#to_csvObject

Returns semi-colon delimited list of tide data.



30
31
32
# File 'lib/tide.rb', line 30

def to_csv
  @csv ||= format_csv
end

#to_htmlObject

Returns formatted html table of tide data.



35
36
37
# File 'lib/tide.rb', line 35

def to_html
  @html ||= format_html
end