Class: Zitdunyet::Checkoff
- Inherits:
-
Object
- Object
- Zitdunyet::Checkoff
- Defined in:
- lib/zitdunyet/checkoff.rb
Instance Attribute Summary collapse
-
#hint ⇒ Object
Returns the value of attribute hint.
-
#label ⇒ Object
Returns the value of attribute label.
-
#logic ⇒ Object
Returns the value of attribute logic.
-
#percent ⇒ Object
Returns the value of attribute percent.
-
#stale ⇒ Object
Returns the value of attribute stale.
-
#units ⇒ Object
Returns the value of attribute units.
-
#when ⇒ Object
Returns the value of attribute when.
Instance Method Summary collapse
- #assign_options(opts) ⇒ Object
- #assign_progress(progress_amount) ⇒ Object
-
#initialize(label, progress_amount, *opts, &logic) ⇒ Checkoff
constructor
A new instance of Checkoff.
Constructor Details
#initialize(label, progress_amount, *opts, &logic) ⇒ Checkoff
Returns a new instance of Checkoff.
5 6 7 8 9 10 11 12 13 |
# File 'lib/zitdunyet/checkoff.rb', line 5 def initialize(label, progress_amount, *opts, &logic) # Fill in the required fields (label.is_a? String) ? self.label = label : (raise ArgumentError.new "Label must be a String") assign_progress(progress_amount) block_given? ? self.logic = logic : (raise ArgumentError.new "Missing the block for assessing completion") # Fill in the optional fields if present (opts) unless opts.empty? end |
Instance Attribute Details
#hint ⇒ Object
Returns the value of attribute hint.
3 4 5 |
# File 'lib/zitdunyet/checkoff.rb', line 3 def hint @hint end |
#label ⇒ Object
Returns the value of attribute label.
3 4 5 |
# File 'lib/zitdunyet/checkoff.rb', line 3 def label @label end |
#logic ⇒ Object
Returns the value of attribute logic.
3 4 5 |
# File 'lib/zitdunyet/checkoff.rb', line 3 def logic @logic end |
#percent ⇒ Object
Returns the value of attribute percent.
3 4 5 |
# File 'lib/zitdunyet/checkoff.rb', line 3 def percent @percent end |
#stale ⇒ Object
Returns the value of attribute stale.
3 4 5 |
# File 'lib/zitdunyet/checkoff.rb', line 3 def stale @stale end |
#units ⇒ Object
Returns the value of attribute units.
3 4 5 |
# File 'lib/zitdunyet/checkoff.rb', line 3 def units @units end |
#when ⇒ Object
Returns the value of attribute when.
3 4 5 |
# File 'lib/zitdunyet/checkoff.rb', line 3 def when @when end |
Instance Method Details
#assign_options(opts) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/zitdunyet/checkoff.rb', line 15 def (opts) = opts.first self.hint = .delete(:hint) #self.stale = options.delete(:stale) #self.when = options.delete(:when) raise ArgumentError.new "Unrecognized options: #{.inspect}" unless .empty? #if self.stale or self.when # raise ArgumentError.new "Specified 'stale' without 'when'" unless self.when # raise ArgumentError.new "Specified 'when' without 'stale'" unless self.stale #end end |
#assign_progress(progress_amount) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/zitdunyet/checkoff.rb', line 28 def assign_progress(progress_amount) if progress_amount.is_a? Zitdunyet::Unit self.units=progress_amount.amount elsif progress_amount.is_a? Zitdunyet::Percent self.percent=progress_amount.amount elsif progress_amount.is_a? Numeric self.percent=progress_amount else raise ArgumentError.new "Invalid type for progress amount: #{progress_amount.class}" end end |