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.



9
10
11
# File 'app/models/effective/post.rb', line 9

def current_user
  @current_user
end

Instance Method Details

#approve!Object



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

def approve!
  update!(draft: false)
end

#approved?Boolean

Returns:

  • (Boolean)


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

def approved?
  draft == false
end

#duplicateObject

Returns a duplicated post object, or throws an exception



131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/models/effective/post.rb', line 131

def duplicate
  post = Post.new(attributes.except('id', 'updated_at', 'created_at', 'tags'))

  post.assign_attributes(
    title: post.title + ' (Copy)',
    slug: post.slug + '-copy',
    draft: true,
    body: body,
    excerpt: excerpt
  )

  post
end

#duplicate!Object



145
146
147
# File 'app/models/effective/post.rb', line 145

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

#event?Boolean

Returns:

  • (Boolean)


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

def event?
  EffectivePosts.event_categories.include?(EffectivePosts.category(category))
end

#published?Boolean

Returns:

  • (Boolean)


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

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

#send_post_submitted!Object



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

def 
  EffectivePosts.send_email(:post_submitted, self)
end

#start_timeObject



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

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.



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

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



101
102
103
# File 'app/models/effective/post.rb', line 101

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