Class: Vintage

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection, Concerns::Percentable, Concerns::Trackable, Mongoid::Document, Mongoid::Search, Mongoid::Timestamps
Defined in:
app/models/vintage.rb

Instance Method Summary collapse

Instance Method Details

#displayed_nameObject



90
91
92
# File 'app/models/vintage.rb', line 90

def displayed_name
  "#{self.wine.name} - #{self.title}"
end

#official?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'app/models/vintage.rb', line 105

def official?
  !self.unofficial
end

#unofficial?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'app/models/vintage.rb', line 110

def unofficial?
  self.unofficial
end

#update_average_rank!Object



95
96
97
98
99
100
101
102
# File 'app/models/vintage.rb', line 95

def update_average_rank!
  if self.user_comments.size > 0
    self.average_rank = self.user_comments.inject(0.0) { |sum, el| sum + el.rank } / self.user_comments.size
  else
    self.average_rank = 0
  end
  self.save!
end