Class: Effective::Post

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user.



23
24
25
# File 'app/models/effective/post.rb', line 23

def current_user
  @current_user
end

Instance Method Details

#approve!Object



154
155
156
# File 'app/models/effective/post.rb', line 154

def approve!
  update!(draft: false)
end

#approved?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'app/models/effective/post.rb', line 117

def approved?
  draft == false
end

#duplicateObject

Returns a duplicated post object, or throws an exception



139
140
141
142
143
144
145
146
147
148
# File 'app/models/effective/post.rb', line 139

def duplicate
  Post.new(attributes.except('id', 'updated_at', 'created_at')).tap do |post|
    post.title = post.title + ' (Copy)'
    post.slug = post.slug + '-copy'
    post.draft = true

    post.body = body
    post.excerpt = excerpt
  end
end

#duplicate!Object



150
151
152
# File 'app/models/effective/post.rb', line 150

def duplicate!
  duplicate.tap { |post| post.save! }
end

#event?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'app/models/effective/post.rb', line 121

def event?
  category == 'events'
end

#published?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'app/models/effective/post.rb', line 113

def published?
  !draft? && published_at.present? && published_at < Time.zone.now
end

#send_post_submitted!Object



134
135
136
# File 'app/models/effective/post.rb', line 134

def 
  EffectivePosts.send_email(:post_submitted, self)
end

#start_timeObject



125
126
127
# File 'app/models/effective/post.rb', line 125

def start_time
  start_at
end

#time_to_read_in_seconds(reading_speed = 3.333) ⇒ Object

3.333 words/second is the default reading speed.



130
131
132
# File 'app/models/effective/post.rb', line 130

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_sObject



109
110
111
# File 'app/models/effective/post.rb', line 109

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