Class: Hospital::Checkup

Inherits:
Object
  • Object
show all
Defined in:
lib/hospital/checkup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/hospital/checkup.rb', line 5

def code
  @code
end

#conditionObject (readonly)

Returns the value of attribute condition.



5
6
7
# File 'lib/hospital/checkup.rb', line 5

def condition
  @condition
end

#diagnosisObject (readonly)

Returns the value of attribute diagnosis.



5
6
7
# File 'lib/hospital/checkup.rb', line 5

def diagnosis
  @diagnosis
end

#groupObject (readonly)

Returns the value of attribute group.



5
6
7
# File 'lib/hospital/checkup.rb', line 5

def group
  @group
end

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/hospital/checkup.rb', line 5

def klass
  @klass
end

#preconditionObject (readonly)

Returns the value of attribute precondition.



5
6
7
# File 'lib/hospital/checkup.rb', line 5

def precondition
  @precondition
end

#skippedObject (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.full_message}.\nThis is a bug inside the checkup method that should be fixed!"
end

#reset_diagnosisObject



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

Returns:

  • (Boolean)


35
36
37
# File 'lib/hospital/checkup.rb', line 35

def success?
  diagnosis.success?
end