Class: Effective::Post

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/effective/post.rb

Instance Method Summary collapse

Instance Method Details

#approved?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/effective/post.rb', line 65

def approved?
  draft == false
end

#bodyObject



73
74
75
# File 'app/models/effective/post.rb', line 73

def body
  region(:body).content
end

#body=(input) ⇒ Object



77
78
79
# File 'app/models/effective/post.rb', line 77

def body=(input)
  region(:body).content = input
end

#event?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/effective/post.rb', line 69

def event?
  category == 'events'
end

#send_post_submitted_to_admin!Object



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

def 
  send_email(:post_submitted_to_admin, to_param)
end

#time_to_read_in_seconds(reading_speed = 3.333) ⇒ Object

3.333 words/second is the default reading speed.



86
87
88
# File 'app/models/effective/post.rb', line 86

def time_to_read_in_seconds(reading_speed = 3.333)
  (regions.to_a.sum { |region| (region.content || '').scan(/\w+/).size } / reading_speed).seconds
end

#to_paramObject



81
82
83
# File 'app/models/effective/post.rb', line 81

def to_param
  "#{id}-#{title.parameterize}"
end

#to_sObject



61
62
63
# File 'app/models/effective/post.rb', line 61

def to_s
  title.presence || 'New Post'
end