Class: Zueribad::Bath

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

Constant Summary collapse

SERVICE_URL =
'https://www.stadt-zuerich.ch/stzh/bathdatadownload'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Bath

Returns a new instance of Bath.



18
19
20
21
22
23
24
# File 'lib/zueribad/bath.rb', line 18

def initialize(params = {})
  params.each do |k,v|
    if respond_to? k
      instance_variable_set("@#{k}".to_sym, v)
    end
  end
end

Instance Attribute Details

#modified_atObject

Returns the value of attribute modified_at.



16
17
18
# File 'lib/zueribad/bath.rb', line 16

def modified_at
  @modified_at
end

#nameObject

Returns the value of attribute name.



13
14
15
# File 'lib/zueribad/bath.rb', line 13

def name
  @name
end

#open_statusObject

Returns the value of attribute open_status.



15
16
17
# File 'lib/zueribad/bath.rb', line 15

def open_status
  @open_status
end

#temperatureObject

Returns the value of attribute temperature.



14
15
16
# File 'lib/zueribad/bath.rb', line 14

def temperature
  @temperature
end

Class Method Details

.downloadObject



43
44
45
# File 'lib/zueribad/bath.rb', line 43

def self.download
  open(SERVICE_URL).read
end

.fetch(name = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/zueribad/bath.rb', line 26

def self.fetch(name = nil)
  doc = Nokogiri::Slop(self.download)

  baths = doc.bathinfos.baths.bath.map do |x|
    Bath.new(:name => x.title.content,
             :temperature => x.temperatureWater.content,
             :open_status => x.openClosedTextPlain.content,
             :modified_at => x.dateModified.content)
  end

  if name
    baths.select {|x| x.name =~ /#{name}/i}
  else
    baths
  end
end