Class: Stats

Inherits:
Object show all
Includes:
ActiveModel::Model
Defined in:
app/models/stats.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#failedObject

Returns the value of attribute failed.



4
5
6
# File 'app/models/stats.rb', line 4

def failed
  @failed
end

#passedObject

Returns the value of attribute passed.



4
5
6
# File 'app/models/stats.rb', line 4

def passed
  @passed
end

#passed_with_warningsObject

Returns the value of attribute passed_with_warnings.



4
5
6
# File 'app/models/stats.rb', line 4

def passed_with_warnings
  @passed_with_warnings
end

#unknownObject

Returns the value of attribute unknown.



4
5
6
# File 'app/models/stats.rb', line 4

def unknown
  @unknown
end

Class Method Details

.from_statuses(statuses) ⇒ Object



37
38
39
40
41
42
# File 'app/models/stats.rb', line 37

def self.from_statuses(statuses)
  Stats.new(statuses.inject({passed: 0, passed_with_warnings: 0, failed: 0, unknown: 0}) do |accum, status|
    accum[status.group.to_sym] += 1
    accum
  end)
end

Instance Method Details

#done?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/models/stats.rb', line 22

def done?
  pending == 0
end

#pendingObject



14
15
16
# File 'app/models/stats.rb', line 14

def pending
  failed + unknown
end

#resolvedObject



18
19
20
# File 'app/models/stats.rb', line 18

def resolved
  passed + passed_with_warnings
end

#started?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/stats.rb', line 26

def started?
   > 0
end

#submittedObject



10
11
12
# File 'app/models/stats.rb', line 10

def 
  failed + resolved
end

#to_h(&key) ⇒ Object



30
31
32
33
34
35
# File 'app/models/stats.rb', line 30

def to_h(&key)
  {key.call(:passed) => passed,
   key.call(:passed_with_warnings) => passed_with_warnings,
   key.call(:failed) => failed,
   key.call(:unknown) => unknown}
end

#totalObject



6
7
8
# File 'app/models/stats.rb', line 6

def total
   + unknown
end