Class: PavementConditionIndex::PCI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(score: nil) ⇒ PCI

Returns a new instance of PCI.



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

def initialize(score:nil)
  @score = score
end

Instance Attribute Details

#scoreObject (readonly)

Returns the value of attribute score.



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

def score
  @score
end

Instance Method Details

#colorObject



37
38
39
# File 'lib/pavement_condition_index/pci.rb', line 37

def color
  lookup[:color]
end

#lookupObject



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

def lookup
  @lookup ||= begin
    case @score.to_i
    when 85..100
      {rating: 'Good', color: '0f7d1d'}
    when 70..85
      {rating: 'Satisfactory', color: '1ec734'}
    when 55..70
      {rating: 'Fair', color: 'fefb4a'}
    when 40..55
      {rating: 'Poor', color: 'fc2e1f'}
    when 25..40
      {rating: 'Very Poor', color: 'a81a10'}
    when 10..25
      {rating: 'Serious', color: '690d07'}
    when 0..10
      {rating: 'Failed', color: '979797'}
    else
      {rating: 'ERROR', color: '000000'}
    end
  end
end

#ratingObject



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

def rating
  lookup[:rating]
end