Class: PavementConditionIndex::DistressGroup

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: nil, severity: nil, distresses: nil, size_of_sample_unit: nil, pavement_type: nil) ⇒ DistressGroup

Returns a new instance of DistressGroup.



7
8
9
10
11
12
13
# File 'lib/pavement_condition_index/distress_group.rb', line 7

def initialize(type:nil,severity:nil,distresses:nil,size_of_sample_unit:nil,pavement_type:nil)
  @type = type
  @severity = severity
  @distresses = distresses
  @size_of_sample_unit = size_of_sample_unit
  @pavement_type = pavement_type
end

Instance Attribute Details

#distressesObject (readonly)

Returns the value of attribute distresses.



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

def distresses
  @distresses
end

#pavement_typeObject (readonly)

Returns the value of attribute pavement_type.



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

def pavement_type
  @pavement_type
end

#severityObject (readonly)

Returns the value of attribute severity.



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

def severity
  @severity
end

#size_of_sample_unitObject (readonly)

Returns the value of attribute size_of_sample_unit.



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

def size_of_sample_unit
  @size_of_sample_unit
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#deduct_valueObject



33
34
35
# File 'lib/pavement_condition_index/distress_group.rb', line 33

def deduct_value
  @deduct_value ||= PavementConditionIndex::Lookups::DeductValues.new(pavement_type: @pavement_type, distress_type: @type, severity: @severity).call(density_percentage)
end

#densityObject



19
20
21
22
23
24
25
26
27
# File 'lib/pavement_condition_index/distress_group.rb', line 19

def density
  @density ||= begin
    if @type == :joint_seal_damage 
      1.0
    else
      total_quantity/@size_of_sample_unit.to_f
    end
  end
end

#density_percentageObject



29
30
31
# File 'lib/pavement_condition_index/distress_group.rb', line 29

def density_percentage
  @density_percentage ||= density * 100
end

#total_quantityObject



15
16
17
# File 'lib/pavement_condition_index/distress_group.rb', line 15

def total_quantity
  @total_quantity ||= @distresses.map{|distress| distress[:quantity]}.reduce(:+)
end