Class: ImportManager::Status::Counts
- Inherits:
-
Hash
- Object
- Hash
- ImportManager::Status::Counts
- Defined in:
- lib/import_manager/status/counts.rb
Instance Method Summary collapse
- #count(key) ⇒ Object
- #default(_key) ⇒ Object
-
#initialize(hash) ⇒ Counts
constructor
A new instance of Counts.
- #percentage(key) ⇒ Object
- #step(key) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Counts
Returns a new instance of Counts.
4 5 6 7 |
# File 'lib/import_manager/status/counts.rb', line 4 def initialize hash hash ||= {} replace hash end |
Instance Method Details
#count(key) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/import_manager/status/counts.rb', line 13 def count key if key.is_a? Array key.inject(0) { |sum, k| sum + self[k] } else self[key] end end |
#default(_key) ⇒ Object
9 10 11 |
# File 'lib/import_manager/status/counts.rb', line 9 def default _key 0 end |
#percentage(key) ⇒ Object
25 26 27 28 |
# File 'lib/import_manager/status/counts.rb', line 25 def percentage key return 0 if count(:total) == 0 || count(key).nil? (count(key) / count(:total).to_f * 100).floor(2) end |
#step(key) ⇒ Object
21 22 23 |
# File 'lib/import_manager/status/counts.rb', line 21 def step key self[key] += 1 end |