class LiveJournal::Comment

Attributes

body[RW]
commentid[RW]
itemid[RW]
parentid[RW]
posterid[RW]
state[RW]

State of the comment. Possible values: {:active, :screened, :deleted}

subject[RW]
time[R]

a Ruby Time object

Public Class Methods

new() click to toggle source
# File lib/livejournal/comment.rb, line 38
def initialize
  @commentid = @posterid = @itemid = @parentid = nil
  @subject = @body = nil
  @time = nil
  @state = :active
end
state_from_string(str) click to toggle source

Convert a state to the string representation used by LiveJournal.

# File lib/livejournal/comment.rb, line 46
def self.state_from_string(str)
  case str
  when nil; :active
  when 'A'; :active
  when 'D'; :deleted
  when 'S'; :screened
  when 'F'; :frozen
  else raise ArgumentError, "Invalid comment state: #{str.inspect}"
  end
end
state_to_string(state) click to toggle source

Convert a state from the string representation used by LiveJournal.

# File lib/livejournal/comment.rb, line 58
def self.state_to_string state
  case state
  when nil;       nil
  when :active;   nil
  when :deleted;  'D'
  when :screened; 'S'
  when :frozen;   'F'
  else raise ArgumentError, "Invalid comment state: #{state.inspect}"
  end
end

Public Instance Methods

==(other) click to toggle source
# File lib/livejournal/comment.rb, line 74
def ==(other)
  [:commentid, :posterid, :state, :itemid, :parentid,
   :subject, :body, :time].each do |attr|
    return false if send(attr) != other.send(attr)
  end
  return true
end
load_from_database_row(row) click to toggle source
# File lib/livejournal/database.rb, line 292
def load_from_database_row row
  @commentid, @posterid = row[0].to_i, row[1].to_i
  @itemid, @parentid = row[2].to_i, row[3].to_i
  @state = Comment::state_from_string row[4]
  @subject, @body = row[5], row[6]
  @time = Time.at(row[7]).utc
  self
end
time=(time) click to toggle source
# File lib/livejournal/comment.rb, line 69
def time=(time)
  raise RuntimeError, "Must use GMT times everywhere to reduce confusion.  See LiveJournal::coerce_gmt for details." unless time.gmt?
  @time = time
end
to_database_row() click to toggle source
# File lib/livejournal/database.rb, line 300
def to_database_row
  state = Comment::state_to_string @state
  [@commentid, @posterid, @itemid, @parentid,
   state, @subject, @body, @time.to_i]
end