Class: CamarasValenciaEs::SurveillanceCamera
- Inherits:
-
Object
- Object
- CamarasValenciaEs::SurveillanceCamera
- Includes:
- HTTParty
- Defined in:
- lib/camaras_valencia_es/surveillance_camera.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#icon_type ⇒ Object
Returns the value of attribute icon_type.
-
#id ⇒ Object
Returns the value of attribute id.
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
-
#type ⇒ Object
Returns the value of attribute type.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
- .all(post_id) ⇒ Object
-
.parse(json) ⇒ Object
TODO: DRY.
Instance Method Summary collapse
- #image ⇒ Object
-
#initialize(id, x, y, target, source, address, type, icon_type) ⇒ SurveillanceCamera
constructor
A new instance of SurveillanceCamera.
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
#address ⇒ Object
Returns the value of attribute address.
5 6 7 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5 def address @address end |
#icon_type ⇒ Object
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 |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5 def id @id end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
5 6 7 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5 def target @target end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5 def type @type end |
#x ⇒ Object
Returns the value of attribute x.
5 6 7 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 5 def x @x end |
#y ⇒ Object
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
#image ⇒ Object
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 |