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.



12
13
14
# File 'app/models/effective/post.rb', line 12

def current_user
  @current_user
end

Instance Method Details

#approve!Object



157
158
159
# File 'app/models/effective/post.rb', line 157

def approve!
  update!(published_start_at: Time.zone.now)
end

#approved?Boolean

Returns:

  • (Boolean)


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

def approved?
  published?
end

#duplicateObject

Returns a duplicated post object, or throws an exception



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

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

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

  post.assign_attributes(published_start_at: nil, published_end_at: nil)

  post
end

#duplicate!Object



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

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

#event?Boolean

Returns:

  • (Boolean)


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

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

#send_post_submitted!Object



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

def 
  EffectivePosts.send_email(:post_submitted, self)
end

#start_timeObject



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

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.



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

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



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

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