Class: Aerial::Comment
Overview
Anonymous feedback
Instance Attribute Summary collapse
-
#archive_name ⇒ Object
Returns the value of attribute archive_name.
-
#article ⇒ Object
readonly
Returns the value of attribute article.
-
#email ⇒ Object
Returns the value of attribute email.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#homepage ⇒ Object
Returns the value of attribute homepage.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#name ⇒ Object
Returns the value of attribute name.
-
#permalink ⇒ Object
readonly
Returns the value of attribute permalink.
-
#publish_date ⇒ Object
Returns the value of attribute publish_date.
-
#referrer ⇒ Object
Returns the value of attribute referrer.
-
#spam ⇒ Object
Returns the value of attribute spam.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Attributes inherited from Content
Class Method Summary collapse
-
.create(archive_name, attributes = {}) ⇒ Object
Create a new instance and write comment to disk
path
the file location of the comment. -
.open(data, options = {}) ⇒ Object
Open and existing comment
data
contains info about the comment.
Instance Method Summary collapse
-
#archive_path ⇒ Object
The absolute file path of the archive.
-
#expand_file ⇒ Object
Absolute path of the comment file.
-
#generate_name! ⇒ Object
Create a unique file name for this comment.
-
#initialize(atts = {}) ⇒ Comment
constructor
A new instance of Comment.
-
#save(archive_name) ⇒ Object
Save the instance to disk
archive_name
the parent directory of the article, we’re forcing the parameter to ensure the archive_name is established before attemping to write it to disk. -
#suspicious? ⇒ Boolean
Ask Akismetor if comment is spam.
-
#to_s ⇒ Object
String representation.
-
#valid? ⇒ Boolean
Make sure comment has the required data.
Constructor Details
#initialize(atts = {}) ⇒ Comment
Returns a new instance of Comment.
10 11 12 13 |
# File 'lib/aerial/comment.rb', line 10 def initialize(atts = {}) super sanitize_url end |
Instance Attribute Details
#archive_name ⇒ Object
Returns the value of attribute archive_name.
7 8 9 |
# File 'lib/aerial/comment.rb', line 7 def archive_name @archive_name end |
#article ⇒ Object (readonly)
Returns the value of attribute article.
6 7 8 |
# File 'lib/aerial/comment.rb', line 6 def article @article end |
#email ⇒ Object
Returns the value of attribute email.
7 8 9 |
# File 'lib/aerial/comment.rb', line 7 def email @email end |
#file_name ⇒ Object
Returns the value of attribute file_name.
7 8 9 |
# File 'lib/aerial/comment.rb', line 7 def file_name @file_name end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
6 7 8 |
# File 'lib/aerial/comment.rb', line 6 def file_path @file_path end |
#homepage ⇒ Object
Returns the value of attribute homepage.
7 8 9 |
# File 'lib/aerial/comment.rb', line 7 def homepage @homepage end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/aerial/comment.rb', line 6 def id @id end |
#ip ⇒ Object
Returns the value of attribute ip.
7 8 9 |
# File 'lib/aerial/comment.rb', line 7 def ip @ip end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/aerial/comment.rb', line 7 def name @name end |
#permalink ⇒ Object (readonly)
Returns the value of attribute permalink.
6 7 8 |
# File 'lib/aerial/comment.rb', line 6 def permalink @permalink end |
#publish_date ⇒ Object
Returns the value of attribute publish_date.
7 8 9 |
# File 'lib/aerial/comment.rb', line 7 def publish_date @publish_date end |
#referrer ⇒ Object
Returns the value of attribute referrer.
7 8 9 |
# File 'lib/aerial/comment.rb', line 7 def referrer @referrer end |
#spam ⇒ Object
Returns the value of attribute spam.
6 7 8 |
# File 'lib/aerial/comment.rb', line 6 def spam @spam end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
7 8 9 |
# File 'lib/aerial/comment.rb', line 7 def user_agent @user_agent end |
Class Method Details
.create(archive_name, attributes = {}) ⇒ Object
Create a new instance and write comment to disk
+path+ the file location of the comment
21 22 23 24 25 26 27 |
# File 'lib/aerial/comment.rb', line 21 def self.create(archive_name, attributes ={}) comment = Comment.new(attributes.merge(:archive_name => archive_name)) if comment.valid? return self.save_new(comment) end false end |
.open(data, options = {}) ⇒ Object
Open and existing comment
+data+ contains info about the comment
31 32 33 |
# File 'lib/aerial/comment.rb', line 31 def self.open(data, ={}) self.new( self.extract_comment_from(data, ) ) end |
Instance Method Details
#archive_path ⇒ Object
The absolute file path of the archive
56 57 58 |
# File 'lib/aerial/comment.rb', line 56 def archive_path File.join(Aerial.repo.working_dir, Aerial.config.articles.dir, self.archive_name) end |
#expand_file ⇒ Object
Absolute path of the comment file
50 51 52 53 |
# File 'lib/aerial/comment.rb', line 50 def return unless self.archive_name File.join(self.archive_path, self.name) end |
#generate_name! ⇒ Object
Create a unique file name for this comment
73 74 75 76 77 78 |
# File 'lib/aerial/comment.rb', line 73 def generate_name! return self.name unless self.name.nil? extenstion = self.suspicious? ? "spam" : "comment" self.name = "#{DateTime.now.strftime("%Y%m%d%H%d%S")}_#{self.email}.#{extenstion}" end |
#save(archive_name) ⇒ Object
Save the instance to disk
+archive_name+ the parent directory of the article, we're forcing the parameter to ensure
the archive_name is established before attemping to write it to disk
42 43 44 45 46 47 |
# File 'lib/aerial/comment.rb', line 42 def save(archive_name) self.archive_name = archive_name if File.directory? self.archive_path Comment.save_new(self) end end |
#suspicious? ⇒ Boolean
Ask Akismetor if comment is spam
67 68 69 70 |
# File 'lib/aerial/comment.rb', line 67 def suspicious? return self.spam if self.spam self.spam = Akismetor.spam?() end |
#to_s ⇒ Object
String representation
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/aerial/comment.rb', line 81 def to_s me = "" me << "Author: #{self.} \n" if self. me << "Publish Date: #{self.publish_date} \n" if self.publish_date.to_s me << "Email: #{self.email} \n" if self.email me << "Homepage: #{self.homepage} \n" if self.homepage me << "User IP: #{self.ip} \n" if self.ip me << "User Agent: #{self.user_agent} \n" if self.user_agent me << "Spam?: #{self.spam} \n" if self.spam me << "\n#{self.body}" if self.body return me end |
#valid? ⇒ Boolean
Make sure comment has the required data
61 62 63 64 |
# File 'lib/aerial/comment.rb', line 61 def valid? return false if self.email.blank? || self..blank? || self.body.blank? true end |