Class: Aerial::Comment

Inherits:
Content show all
Defined in:
lib/aerial/comment.rb

Overview

Anonymous feedback

Instance Attribute Summary collapse

Attributes inherited from Content

#author, #body, #title

Class Method Summary collapse

Instance Method Summary collapse

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_nameObject

Returns the value of attribute archive_name.



7
8
9
# File 'lib/aerial/comment.rb', line 7

def archive_name
  @archive_name
end

#articleObject (readonly)

Returns the value of attribute article.



6
7
8
# File 'lib/aerial/comment.rb', line 6

def article
  @article
end

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/aerial/comment.rb', line 7

def email
  @email
end

#file_nameObject

Returns the value of attribute file_name.



7
8
9
# File 'lib/aerial/comment.rb', line 7

def file_name
  @file_name
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



6
7
8
# File 'lib/aerial/comment.rb', line 6

def file_path
  @file_path
end

#homepageObject

Returns the value of attribute homepage.



7
8
9
# File 'lib/aerial/comment.rb', line 7

def homepage
  @homepage
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/aerial/comment.rb', line 6

def id
  @id
end

#ipObject

Returns the value of attribute ip.



7
8
9
# File 'lib/aerial/comment.rb', line 7

def ip
  @ip
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/aerial/comment.rb', line 7

def name
  @name
end

Returns the value of attribute permalink.



6
7
8
# File 'lib/aerial/comment.rb', line 6

def permalink
  @permalink
end

#publish_dateObject

Returns the value of attribute publish_date.



7
8
9
# File 'lib/aerial/comment.rb', line 7

def publish_date
  @publish_date
end

#referrerObject

Returns the value of attribute referrer.



7
8
9
# File 'lib/aerial/comment.rb', line 7

def referrer
  @referrer
end

#spamObject

Returns the value of attribute spam.



6
7
8
# File 'lib/aerial/comment.rb', line 6

def spam
  @spam
end

#user_agentObject

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, options={})
  self.new( self.extract_comment_from(data, options) )
end

Instance Method Details

#archive_pathObject

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_fileObject

Absolute path of the comment file



50
51
52
53
# File 'lib/aerial/comment.rb', line 50

def expand_file
  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

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/aerial/comment.rb', line 67

def suspicious?
  return self.spam if self.spam
  self.spam = Akismetor.spam?(akismet_attributes)
end

#to_sObject

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.author} \n" if self.author
  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

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/aerial/comment.rb', line 61

def valid?
  return false if self.email.blank? || self.author.blank? || self.body.blank?
  true
end