Class: LiveJournal::Comment

Inherits:
Object
  • Object
show all
Defined in:
lib/livejournal/comment.rb,
lib/livejournal/database.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeComment

Returns a new instance of Comment.



38
39
40
41
42
43
# File 'lib/livejournal/comment.rb', line 38

def initialize
  @commentid = @posterid = @itemid = @parentid = nil
  @subject = @body = nil
  @time = nil
  @state = :active
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



34
35
36
# File 'lib/livejournal/comment.rb', line 34

def body
  @body
end

#commentidObject

Returns the value of attribute commentid.



31
32
33
# File 'lib/livejournal/comment.rb', line 31

def commentid
  @commentid
end

#itemidObject

Returns the value of attribute itemid.



31
32
33
# File 'lib/livejournal/comment.rb', line 31

def itemid
  @itemid
end

#parentidObject

Returns the value of attribute parentid.



31
32
33
# File 'lib/livejournal/comment.rb', line 31

def parentid
  @parentid
end

#posteridObject

Returns the value of attribute posterid.



31
32
33
# File 'lib/livejournal/comment.rb', line 31

def posterid
  @posterid
end

#stateObject

State of the comment. Possible values: :screened, :deleted



33
34
35
# File 'lib/livejournal/comment.rb', line 33

def state
  @state
end

#subjectObject

Returns the value of attribute subject.



34
35
36
# File 'lib/livejournal/comment.rb', line 34

def subject
  @subject
end

#timeObject

a Ruby Time object



36
37
38
# File 'lib/livejournal/comment.rb', line 36

def time
  @time
end

Class Method Details

.state_from_string(str) ⇒ Object

Convert a state to the string representation used by LiveJournal.



46
47
48
49
50
51
52
53
54
55
# 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) ⇒ Object

Convert a state from the string representation used by LiveJournal.



58
59
60
61
62
63
64
65
66
67
# 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

Instance Method Details

#==(other) ⇒ Object



74
75
76
77
78
79
80
# 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) ⇒ Object



292
293
294
295
296
297
298
299
# 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

#to_database_rowObject



300
301
302
303
304
# 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