Class: Hospital::Checkup
- Inherits:
-
Object
- Object
- Hospital::Checkup
- Defined in:
- lib/hospital/checkup.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#diagnosis ⇒ Object
readonly
Returns the value of attribute diagnosis.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#precondition ⇒ Object
readonly
Returns the value of attribute precondition.
-
#skipped ⇒ Object
readonly
Returns the value of attribute skipped.
Instance Method Summary collapse
- #check(verbose: false, ignore_condition: false) ⇒ Object
-
#initialize(klass, code, title: nil, condition: -> { true }, precondition: false) ⇒ Checkup
constructor
A new instance of Checkup.
- #reset_diagnosis ⇒ Object
- #set_group(group) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(klass, code, title: nil, condition: -> { true }, precondition: false) ⇒ Checkup
Returns a new instance of Checkup.
7 8 9 10 11 12 13 14 |
# File 'lib/hospital/checkup.rb', line 7 def initialize klass, code, title: nil, condition: -> { true }, precondition: false @klass = klass @code = code @condition = condition @diagnosis = Hospital::Diagnosis.new([klass.to_s, title].compact.join(' - ')) @precondition = precondition @group = nil end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
5 6 7 |
# File 'lib/hospital/checkup.rb', line 5 def code @code end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
5 6 7 |
# File 'lib/hospital/checkup.rb', line 5 def condition @condition end |
#diagnosis ⇒ Object (readonly)
Returns the value of attribute diagnosis.
5 6 7 |
# File 'lib/hospital/checkup.rb', line 5 def diagnosis @diagnosis end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
5 6 7 |
# File 'lib/hospital/checkup.rb', line 5 def group @group end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/hospital/checkup.rb', line 5 def klass @klass end |
#precondition ⇒ Object (readonly)
Returns the value of attribute precondition.
5 6 7 |
# File 'lib/hospital/checkup.rb', line 5 def precondition @precondition end |
#skipped ⇒ Object (readonly)
Returns the value of attribute skipped.
5 6 7 |
# File 'lib/hospital/checkup.rb', line 5 def skipped @skipped end |
Instance Method Details
#check(verbose: false, ignore_condition: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/hospital/checkup.rb', line 20 def check verbose: false, ignore_condition: false diagnosis.reset if ignore_condition || condition.nil? || condition.call @skipped = false code.call(diagnosis) diagnosis else @skipped = true nil end rescue StandardError => e diagnosis.add_error "Unrescued exception in #{klass}.checkup:\n#{e.}.\nThis is a bug inside the checkup method that should be fixed!" end |
#reset_diagnosis ⇒ Object
16 17 18 |
# File 'lib/hospital/checkup.rb', line 16 def reset_diagnosis diagnosis.reset end |
#set_group(group) ⇒ Object
39 40 41 |
# File 'lib/hospital/checkup.rb', line 39 def set_group group @group = group end |
#success? ⇒ Boolean
35 36 37 |
# File 'lib/hospital/checkup.rb', line 35 def success? diagnosis.success? end |