Class: ScavengerHunt::Clue

Inherits:
ApplicationRecord show all
Defined in:
lib/scavenger_hunt/app/models/scavenger_hunt/clue.rb

Instance Method Summary collapse

Methods inherited from ApplicationRecord

hook, position_scope

Instance Method Details

#answered? ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/scavenger_hunt/app/models/scavenger_hunt/clue.rb', line 20

def answered?
  ended_at.present?
end

#first_hint ⇒ Object



24
25
26
# File 'lib/scavenger_hunt/app/models/scavenger_hunt/clue.rb', line 24

def first_hint
  hints.order(Arel.sql(%(used_at NULLS FIRST)), :position).first
end

#next ⇒ Object



28
29
30
# File 'lib/scavenger_hunt/app/models/scavenger_hunt/clue.rb', line 28

def next
  game.clues.unanswered.where("position > ?", position).first
end

#prev ⇒ Object



32
33
34
# File 'lib/scavenger_hunt/app/models/scavenger_hunt/clue.rb', line 32

def prev
  game.clues.unscoped.unanswered.where("position < ?", position).order(position: :desc).first
end