Class: Est::Estimates
- Inherits:
-
Object
- Object
- Est::Estimates
- Defined in:
- lib/est/estimates.rb
Overview
Estimates.
Defined Under Namespace
Classes: Const
Instance Method Summary collapse
-
#initialize(dir) ⇒ Estimates
constructor
Ctor.
-
#iterate ⇒ Object
Iterate them all.
-
#total ⇒ Object
Get total estimate.
Constructor Details
#initialize(dir) ⇒ Estimates
Ctor.
dir
-
Directory with estimates
38 39 40 |
# File 'lib/est/estimates.rb', line 38 def initialize(dir) @dir = dir end |
Instance Method Details
#iterate ⇒ Object
Iterate them all
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/est/estimates.rb', line 57 def iterate unless @iterate if File.exist?(@dir) && File.directory?(@dir) @iterate = Dir.entries(@dir) .reject { |f| f.index('.') == 0 } .select { |f| f =~ /^.*\.est$/ } .map { |f| File.join(@dir, f) } .each { |f| Est.log.info "#{f} found" } .map { |f| Estimate.new(f) } .map { |f| Estimate::Const.new(f) } else Est.log.info "#{@dir} is absent or is not a directory" @iterate = [] end end @iterate end |
#total ⇒ Object
Get total estimate.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/est/estimates.rb', line 43 def total estimates = iterate if estimates.empty? total = 0 else total = estimates.reduce(0) do |a, e| Est.log.info "#{e.date}/#{e.}: #{e.total}" a + e.total end / estimates.size end total end |