Sha256: 65e7673977e86764bcbd9f06ac40973f464721142d06e2058830096ec6b870aa

Contents?: true

Size: 844 Bytes

Versions: 25

Compression:

Stored size: 844 Bytes

Contents

class Stats
  include ActiveModel::Model

  attr_accessor :passed, :passed_with_warnings, :failed, :unknown

  def total
    submitted + unknown
  end

  def submitted
    failed + resolved
  end

  def pending
    failed + unknown
  end

  def resolved
    passed + passed_with_warnings
  end

  def done?
    pending == 0
  end

  def started?
    submitted > 0
  end

  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

  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

  private

  def ratio(x)
    (100 * x / total.to_f).round(2)
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
mumuki-laboratory-5.7.0 app/models/stats.rb
mumuki-laboratory-5.6.3 app/models/stats.rb
mumuki-laboratory-5.6.2 app/models/stats.rb
mumuki-laboratory-5.6.1 app/models/stats.rb
mumuki-laboratory-5.6.0 app/models/stats.rb
mumuki-laboratory-5.5.0 app/models/stats.rb
mumuki-laboratory-5.4.0 app/models/stats.rb
mumuki-laboratory-5.3.0 app/models/stats.rb
mumuki-laboratory-5.2.1 app/models/stats.rb
mumuki-laboratory-5.2.0 app/models/stats.rb
mumuki-laboratory-5.1.1 app/models/stats.rb
mumuki-laboratory-5.1.0 app/models/stats.rb
mumuki-laboratory-5.0.12 app/models/stats.rb
mumuki-laboratory-5.0.11 app/models/stats.rb
mumuki-laboratory-5.0.10 app/models/stats.rb
mumuki-laboratory-5.0.9 app/models/stats.rb
mumuki-laboratory-5.0.8 app/models/stats.rb
mumuki-laboratory-5.0.7 app/models/stats.rb
mumuki-laboratory-5.0.6 app/models/stats.rb
mumuki-laboratory-5.0.5 app/models/stats.rb