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

#duplicate!Object

Returns a duplicated post object, or throws an exception



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/models/effective/post.rb', line 95

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

    if defined?(EffectiveAssets) && image.present?
      post.add_to_asset_box(:image, image)
    end

    regions.each do |region|
      post.regions.build(region.attributes.except('id', 'updated_at', 'created_at'))
    end

    post.save!
  end
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