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



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

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

#approved?Boolean

Returns:

  • (Boolean)


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

def approved?
  published?
end

#duplicateObject

Returns a duplicated post object, or throws an exception



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

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



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

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

#event?Boolean

Returns:

  • (Boolean)


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

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

#send_post_submitted!Object



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

def 
  EffectivePosts.send_email(:post_submitted, self)
end

#start_timeObject



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

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.



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

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



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

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