master
E. Almqvist 3 years ago
parent 715aca819f
commit d502f2816e
  1. 12
      src/db_models.rb

@ -1,6 +1,6 @@
# User table model # User table model
class User < EntityModel class User < EntityModel
attr_reader :email, :name, :bio_text, :balance, :avatar_url, :pw_hash attr_reader :email, :name, :bio_text, :balance, :avatar_url, :pw_hash, :reputation
def initialize(user_info) def initialize(user_info)
super user_info super user_info
@ -41,18 +41,14 @@ class User < EntityModel
md_parser.render @bio_text md_parser.render @bio_text
end end
def reputation
rep = self.get "reputation", "id = ?", @id
rep && rep.to_i
end
def reputation_text def reputation_text
sign = reputation > 0 ? "+" : "" sign = @reputation > 0 ? "+" : ""
return "#{sign}#{reputation}" return "#{sign}#{@reputation}"
end end
def reputation= val def reputation= val
val = val.clamp MIN_REP, MAX_REP val = val.clamp MIN_REP, MAX_REP
@reputation = val
self.update({reputation: val}, "id = ?", @id) self.update({reputation: val}, "id = ?", @id)
end end

Loading…
Cancel
Save