Sha256: 41de92f87e67ce0c6be4c962e3cbca5e157083d2a505e9fd57a8a4d4b961da03
Contents?: true
Size: 1.16 KB
Versions: 7
Compression:
Stored size: 1.16 KB
Contents
module Effective class Post < ActiveRecord::Base acts_as_role_restricted if defined?(EffectiveRoles) acts_as_regionable if defined?(EffectiveRegions) self.table_name = EffectivePosts.posts_table_name.to_s belongs_to :user structure do title :string, :validates => [:presence, :length => {:maximum => 255}] category :string, :validates => [:presence] published_at :datetime, :validates => [:presence] draft :boolean, :default => false tags :text roles_mask :integer, :default => 0 timestamps end scope :drafts, -> { where(:draft => true) } scope :published, -> { where(:draft => false).where("#{EffectivePosts.posts_table_name}.published_at < ?", Time.zone.now) } scope :with_category, proc { |category| where(:category => category.to_s.downcase) } def to_param "#{id}-#{title.parameterize}" end # 3.333 words/second is the default reading speed. def time_to_read_in_seconds(reading_speed = 3.333) (regions.to_a.sum { |region| (region.content || '').scan(/\w+/).size } / reading_speed).seconds end end end
Version data entries
7 entries across 7 versions & 1 rubygems