Class: Outcome
Constant Summary collapse
- FILENAME =
'measures'
Instance Attribute Summary collapse
-
#baseline ⇒ Object
Returns the value of attribute baseline.
-
#baseline_date ⇒ Object
Returns the value of attribute baseline_date.
-
#last_measure ⇒ Object
readonly
Returns the value of attribute last_measure.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#persist ⇒ Object
Returns the value of attribute persist.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#target ⇒ Object
Returns the value of attribute target.
-
#target_date ⇒ Object
Returns the value of attribute target_date.
Instance Method Summary collapse
-
#format_number(measure) ⇒ Object
format number for display (1000000 => 1,000,000) unless number starts with 0 or .
-
#initialize(name, scale, persist = false) ⇒ Outcome
constructor
register a name (String) and scale (Scale) of measurement at creation time.
-
#measure ⇒ Object
perform the measurement using the provide scale delegate the details to any class extending Scale TODO: Change measurement to benchmark.
-
#report ⇒ Object
used to report progress towards goals.
Constructor Details
#initialize(name, scale, persist = false) ⇒ Outcome
register a name (String) and scale (Scale) of measurement at creation time
20 21 22 23 24 25 26 |
# File 'lib/mobiusloop/outcome.rb', line 20 def initialize(name, scale, persist = false) raise "name must not be nil" if name == nil raise "scale must be of type Scale" unless scale.is_a? Scale @name = name @scale = scale @persist = persist end |
Instance Attribute Details
#baseline ⇒ Object
Returns the value of attribute baseline.
11 12 13 |
# File 'lib/mobiusloop/outcome.rb', line 11 def baseline @baseline end |
#baseline_date ⇒ Object
Returns the value of attribute baseline_date.
12 13 14 |
# File 'lib/mobiusloop/outcome.rb', line 12 def baseline_date @baseline_date end |
#last_measure ⇒ Object (readonly)
Returns the value of attribute last_measure.
17 18 19 |
# File 'lib/mobiusloop/outcome.rb', line 17 def last_measure @last_measure end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/mobiusloop/outcome.rb', line 10 def name @name end |
#persist ⇒ Object
Returns the value of attribute persist.
16 17 18 |
# File 'lib/mobiusloop/outcome.rb', line 16 def persist @persist end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
15 16 17 |
# File 'lib/mobiusloop/outcome.rb', line 15 def scale @scale end |
#target ⇒ Object
Returns the value of attribute target.
13 14 15 |
# File 'lib/mobiusloop/outcome.rb', line 13 def target @target end |
#target_date ⇒ Object
Returns the value of attribute target_date.
14 15 16 |
# File 'lib/mobiusloop/outcome.rb', line 14 def target_date @target_date end |
Instance Method Details
#format_number(measure) ⇒ Object
format number for display (1000000 => 1,000,000) unless number starts with 0 or .
52 53 54 55 56 57 58 |
# File 'lib/mobiusloop/outcome.rb', line 52 def format_number(measure) if measure != nil || measure.value != nil whole, decimal = measure.value.to_s.split(".") whole_with_commas = whole.chars.to_a.reverse.each_slice(3).map(&:join).join(",").reverse [whole_with_commas, decimal].compact.join(".") end end |
#measure ⇒ Object
perform the measurement using the provide scale delegate the details to any class extending Scale TODO: Change measurement to benchmark
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mobiusloop/outcome.rb', line 31 def measure begin start_time = Time.now @last_measure = @scale.measure elapsed_time = (Time.now - start_time) return "Success! Measured " + format_number(@last_measure) + " " + @name + " in #{elapsed_time.round(1)} seconds!" rescue Exception => e return "Error! Measurement failed with message: " + e. end end |
#report ⇒ Object
used to report progress towards goals
43 44 45 46 47 48 |
# File 'lib/mobiusloop/outcome.rb', line 43 def report report = "" report << report_progress report << report_remaining report end |