class Token

Public Instance Methods

decrease_tokens() click to toggle source

Each test will decrease the number of tokens by one

# File app/models/token.rb, line 21
def decrease_tokens
  if self.tokens > 0
    self.tokens = self.tokens - 1
    self.last_token_used_date = Date.today
  end
  self.save
end
last_used_date() click to toggle source
# File app/models/token.rb, line 9
def last_used_date
  if self.last_token_used_date
    if Time.zone.parse(self.last_token_used_date.to_s).nil?
      errors.add :last_token_used_date, 'is not a valid date'
      return false
    else return true
    end
  end
end
reassign_tokens() click to toggle source

Re-assign to the student the nomber of tokens allowed for this assignment

# File app/models/token.rb, line 37
def reassign_tokens
  assignment = self.grouping.assignment
  if assignment.tokens_per_day.nil?
    self.tokens = 0
  else
    self.tokens = assignment.tokens_per_day
  end
  self.save
end
reassign_tokens_if_new_day() click to toggle source
# File app/models/token.rb, line 29
def reassign_tokens_if_new_day
  if self.last_token_used_date and self.last_token_used_date < Date.today
    self.reassign_tokens
  end
end
update_tokens(old_limit, new_limit) click to toggle source

Update the number of tokens based on the old and new token limits

# File app/models/token.rb, line 48
def update_tokens(old_limit, new_limit)
  difference = new_limit - old_limit
  self.tokens = [self.tokens + difference, 0].max
  self.save
end