Class: CamarasValenciaEs::SurveillanceCamera

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/camaras_valencia_es/surveillance_camera.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, x, y, target, source, address, type, icon_type) ⇒ SurveillanceCamera

Returns a new instance of SurveillanceCamera.



7
8
9
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 7

def initialize(id, x, y, target, source, address, type, icon_type)
  @id, @x, @y, @target, @source, @address, @type, @icon_type = id, x, y, target, source, address, type, icon_type
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



5
6
7
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5

def address
  @address
end

#icon_typeObject

Returns the value of attribute icon_type.



5
6
7
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5

def icon_type
  @icon_type
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5

def id
  @id
end

#sourceObject

Returns the value of attribute source.



5
6
7
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5

def source
  @source
end

#targetObject

Returns the value of attribute target.



5
6
7
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5

def target
  @target
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5

def type
  @type
end

#xObject

Returns the value of attribute x.



5
6
7
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5

def x
  @x
end

#yObject

Returns the value of attribute y.



5
6
7
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5

def y
  @y
end

Class Method Details

.all(post_id) ⇒ Object



34
35
36
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 34

def self.all(post_id)
  self.parse SurveillanceCamera.get('/infocamaras.asp', query: { idgrupo: post_id}).body
end

.parse(json) ⇒ Object

TODO: DRY. Check SurveillancePost.parse



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 12

def self.parse(json)
  defuck_coords = ->(v) {
    CGI.unescape(v).gsub(/,/,".").to_f
  }

  serializable = JSON.parse(json)
  # This JSON structure is fucking weird just for representing
  # a simple array of objects. An Array of Hashe would have been more than enough.
  # What they call latitude, and longitude is in fact UTM X/Y.
  attrs = serializable['datos']
  attrs['idcamara'].collect.with_index { |idgrupo, i|
    x, y = defuck_coords.call(attrs['latitud'][i]), defuck_coords.call(attrs['longitud'][i])
    target, source, address = CGI.unescape(attrs['destino'][i]), CGI.unescape(attrs['origen'][i]), CGI.unescape(attrs['direccion'][i])
    self.new(attrs['idcamara'][i], x, y, target, source, address, attrs['tipo'][i], attrs['tipoicono'][i])
  }
end

Instance Method Details

#imageObject



38
39
40
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 38

def image
  CGI.unescape SurveillanceCamera.get('/imagen.asp', query: { idcamara: self.id}).body
end