Class: CamarasValenciaEs::SurveillanceCamera
- Inherits:
-
Object
- Object
- CamarasValenciaEs::SurveillanceCamera
- Includes:
- Util::LatLonConverter, Util::V8Unescaper, 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
- #filename ⇒ Object
-
#initialize(id, x, y, target, source, address, type, icon_type) ⇒ SurveillanceCamera
constructor
A new instance of SurveillanceCamera.
- #media ⇒ Object
-
#to_attributes ⇒ Object
TODO.
Methods included from Util::V8Unescaper
Constructor Details
#initialize(id, x, y, target, source, address, type, icon_type) ⇒ SurveillanceCamera
Returns a new instance of SurveillanceCamera.
10 11 12 13 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 10 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 convert_to_lat_long end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
8 9 10 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 8 def address @address end |
#icon_type ⇒ Object
Returns the value of attribute icon_type.
8 9 10 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 8 def icon_type @icon_type end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 8 def id @id end |
#source ⇒ Object
Returns the value of attribute source.
8 9 10 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 8 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
8 9 10 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 8 def target @target end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 8 def type @type end |
#x ⇒ Object
Returns the value of attribute x.
8 9 10 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 8 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
8 9 10 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 8 def y @y end |
Class Method Details
.all(post_id) ⇒ Object
38 39 40 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 38 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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 16 def self.parse(json) defuck_coords = ->(v) { 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 Hashes would have been more than enough. # What they call latitude, and longitude is in fact EPSG 23030 - ed50 / utm zone 30n. attrs = serializable['datos'] attrs['idcamara'].collect.with_index { |idgrupo, i| x, y = defuck_coords.call(attrs['longitud'][i]), defuck_coords.call(attrs['latitud'][i]) target, source, address = unescape(attrs['destino'][i]), unescape(attrs['origen'][i]), unescape(attrs['direccion'][i]) self.new(attrs['idcamara'][i], x, y, target, source, address, attrs['tipo'][i], attrs['tipoicono'][i]) } end |
Instance Method Details
#filename ⇒ Object
42 43 44 45 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 42 def filename @flags_and_filename ||= unescape(SurveillanceCamera.get('/imagen.asp', query: { idcamara: self.id}).body).split(';') @flags_and_filename[1] end |
#media ⇒ Object
47 48 49 50 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 47 def media @flags_and_filename ||= unescape(SurveillanceCamera.get('/imagen.asp', query: { idcamara: self.id}).body).split(';') (@flags_and_filename[0] == '0')? :image : :video end |
#to_attributes ⇒ Object
TODO
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/camaras_valencia_es/surveillance_camera.rb', line 53 def to_attributes { location: [self.latlon.y, self.latlon.x], remote_id: self.id, media: self.media, filename: self.filename, recording_source: self.source, recording_target: self.target } end |