class Law::Judgement

Attributes

applied_regulations[R]
petition[R]
violations[R]

Public Class Methods

judge(petition) click to toggle source
# File lib/law/judgement.rb, line 11
def judge(petition)
  new(petition).judge
end
judge!(petition) click to toggle source
# File lib/law/judgement.rb, line 7
def judge!(petition)
  new(petition).judge!
end
new(petition) click to toggle source
# File lib/law/judgement.rb, line 20
def initialize(petition)
  @petition = petition
  @violations = []
  @applied_regulations = []
end

Public Instance Methods

adjudicated?() click to toggle source
# File lib/law/judgement.rb, line 26
def adjudicated?
  applied_regulations.present?
end
authorized?() click to toggle source
# File lib/law/judgement.rb, line 30
def authorized?
  adjudicated? && violations.blank?
end
judge() click to toggle source
# File lib/law/judgement.rb, line 34
def judge
  judge!
rescue NotAuthorizedError => exception
  error :not_authorized, exception: exception
  false
end
judge!() click to toggle source
# 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

Private Instance Methods

ensure_jurisdiction() click to toggle source
# File lib/law/judgement.rb, line 57
def ensure_jurisdiction
  raise InjunctionError if applicable_regulations.blank?
  raise ComplianceError unless compliant?
end
reckon!() click to toggle source
# File lib/law/judgement.rb, line 62
def reckon!
  @applied_regulations = applicable_regulations.map { |regulation| regulation.new(petition: petition) }
  @violations = applied_regulations.reject(&:valid?)
  raise NotAuthorizedError unless authorized?
end