Class: Zitdunyet::Checkoff

Inherits:
Object
  • Object
show all
Defined in:
lib/zitdunyet/checkoff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  assign_options(opts) unless opts.empty?
end

Instance Attribute Details

#hintObject

Returns the value of attribute hint.



3
4
5
# File 'lib/zitdunyet/checkoff.rb', line 3

def hint
  @hint
end

#labelObject

Returns the value of attribute label.



3
4
5
# File 'lib/zitdunyet/checkoff.rb', line 3

def label
  @label
end

#logicObject

Returns the value of attribute logic.



3
4
5
# File 'lib/zitdunyet/checkoff.rb', line 3

def logic
  @logic
end

#percentObject

Returns the value of attribute percent.



3
4
5
# File 'lib/zitdunyet/checkoff.rb', line 3

def percent
  @percent
end

#staleObject

Returns the value of attribute stale.



3
4
5
# File 'lib/zitdunyet/checkoff.rb', line 3

def stale
  @stale
end

#unitsObject

Returns the value of attribute units.



3
4
5
# File 'lib/zitdunyet/checkoff.rb', line 3

def units
  @units
end

#whenObject

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 assign_options(opts)
  options = opts.first
  self.hint = options.delete(:hint)
  #self.stale = options.delete(:stale)
  #self.when = options.delete(:when)
  raise ArgumentError.new "Unrecognized options: #{options.inspect}" unless options.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