Class: Dimension

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bestObject

Returns the value of attribute best.



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

def best
  @best
end

#maxObject

Returns the value of attribute max.



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

def max
  @max
end

#minObject

Returns the value of attribute min.



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

def min
  @min
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#step_to_bestObject

Returns the value of attribute step_to_best.



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

def step_to_best
  @step_to_best
end

#step_to_worstObject

Returns the value of attribute step_to_worst.



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

def step_to_worst
  @step_to_worst
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

#valuesObject

Returns the value of attribute values.



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

def values
  @values
end

#worstObject

Returns the value of attribute worst.



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

def worst
  @worst
end

Class Method Details

.parse(dim_doc) ⇒ Object

parse the nokogiri doc and extract the dimension propreties it contains



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dimension.rb', line 27

def self.parse(dim_doc)
  d = self.new
  
  # extract dimension name
  d.name = dim_doc[:id]
  
  # extract dimension type
  dim_doc.css('.type').each { |t| d.type =  t.inner_text}
  
  # extract dimension type
  d.values = [];dim_doc.css('.values > .value').each { |vs| d.values << vs.inner_text}
  
  # extract the remaining properties of the dimension
  [:type, :best, :worst, :min, :max, :step_to_best,:step_to_worst].each do |arg|
    dim_doc.css(".#{arg.to_s}").each do |elem| 
      d.send("#{arg}=", elem.inner_text)
    end
  end
  #puts "dimension object : #{d.name.to_s}"
  return d    
end

Instance Method Details

#to_hObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dimension.rb', line 13

def to_h
  h = {}
  h[:type]=@type unless @type.nil?
  h[:values]=@values unless @values.nil? or @values.empty?
  h[:best]=@best unless @best.nil?
  h[:worst]=@worst unless @worst.nil?
  h[:min]=@min unless @min.nil?
  h[:max]=@max unless @max.nil?
  h[:step_to_best]=@step_to_best unless @step_to_best.nil?
  h[:step_to_worst]=@step_to_worst unless @step_to_worst.nil?
  {@name=>h}
end

#to_jsonObject



8
9
10
11
# File 'lib/dimension.rb', line 8

def to_json
  h = to_h
  h.to_json
end