Class: Geostats::Views::DifficultyTerrainMatrix

Inherits:
Base
  • Object
show all
Defined in:
lib/geostats/views/difficulty_terrain_matrix.rb

Constant Summary collapse

STEPS =
[1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]

Instance Method Summary collapse

Constructor Details

#initializeDifficultyTerrainMatrix

Returns a new instance of DifficultyTerrainMatrix.



6
7
8
# File 'lib/geostats/views/difficulty_terrain_matrix.rb', line 6

def initialize
  @matrix = Stats.difficulty_terrain_matrix
end

Instance Method Details

#matrixObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/geostats/views/difficulty_terrain_matrix.rb', line 10

def matrix
  difficulties = STEPS.reverse

  @matrix.map do |row|
    hash = {
      :difficulty => difficulties.pop,
      :dsum => row.sum,
    }

    STEPS.length.times do |i|
      hash["t#{STEPS[i].to_s.gsub(".", "")}"] = row[i] > 0 ? row[i] : nil
    end

    hash
  end
end

#tsumsObject



27
28
29
30
31
# File 'lib/geostats/views/difficulty_terrain_matrix.rb', line 27

def tsums
  STEPS.length.times.to_a.map do |i|
    { :sum => STEPS.length.times.to_a.map { |j| @matrix[j][i] }.sum }
  end
end