Class: Desmoservice::Ventilation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVentilation

Returns a new instance of Ventilation.



6
7
8
# File 'lib/ventilation.rb', line 6

def initialize
  @sectors = Array.new
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/ventilation.rb', line 4

def error
  @error
end

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/ventilation.rb', line 4

def root
  @root
end

#sectorsObject (readonly)

Returns the value of attribute sectors.



4
5
6
# File 'lib/ventilation.rb', line 4

def sectors
  @sectors
end

Instance Method Details

#get_sector_by_id(id) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ventilation.rb', line 34

def get_sector_by_id(id)
  @sectors.each do |sector|
    if sector.id == id
      return sector
    end
    subsector = sector.get_subsector_by_id(id)
    if not subsector.nil?
      return subsector
    end
  end
  return nil
end

#has_error?Boolean

Returns:

  • (Boolean)


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

def has_error?
  return (not error.nil?)
end

#parse_json(json_string) ⇒ Object



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

def parse_json(json_string)
  data = JSON.parse(json_string)
  if data.has_key?('ventilation')
    @error = nil
    ventilation = data['ventilation']
    if ventilation.has_key?('secteurArray')
      ventilation['secteurArray'].each {|v| @sectors << Sector.new(v)}
    end
    if ventilation.has_key?('root')
      @root  = Term.new(ventilation['root'])
    end
  else 
    if data.has_key?('error')
      @error = Error.from_json_hash(data['error'])
    else
      @error = Error.new("responseError", "response", json_string)
    end
  end
end