Class: Law::Judgement

Inherits:
Spicerack::RootObject
  • Object
show all
Defined in:
lib/law/judgement.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(petition) ⇒ Judgement

Returns a new instance of Judgement.



20
21
22
23
24
# File 'lib/law/judgement.rb', line 20

def initialize(petition)
  @petition = petition
  @violations = []
  @applied_regulations = []
end

Instance Attribute Details

#applied_regulationsObject (readonly)

Returns the value of attribute applied_regulations.



16
17
18
# File 'lib/law/judgement.rb', line 16

def applied_regulations
  @applied_regulations
end

#petitionObject (readonly)

Returns the value of attribute petition.



16
17
18
# File 'lib/law/judgement.rb', line 16

def petition
  @petition
end

#violationsObject (readonly)

Returns the value of attribute violations.



16
17
18
# File 'lib/law/judgement.rb', line 16

def violations
  @violations
end

Class Method Details

.judge(petition) ⇒ Object



11
12
13
# File 'lib/law/judgement.rb', line 11

def judge(petition)
  new(petition).judge
end

.judge!(petition) ⇒ Object



7
8
9
# File 'lib/law/judgement.rb', line 7

def judge!(petition)
  new(petition).judge!
end

Instance Method Details

#adjudicated?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/law/judgement.rb', line 26

def adjudicated?
  applied_regulations.present?
end

#authorized?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/law/judgement.rb', line 30

def authorized?
  adjudicated? && violations.blank?
end

#judgeObject



34
35
36
37
38
39
# File 'lib/law/judgement.rb', line 34

def judge
  judge!
rescue NotAuthorizedError => exception
  error :not_authorized, exception: exception
  false
end

#judge!Object

Raises:



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/law/judgement.rb', line 41

def judge!
  raise AlreadyJudgedError if adjudicated?

  if statute&.unregulated?
    @applied_regulations = [ nil ]
    return true
  end

  ensure_jurisdiction
  reckon!

  true
end