Class: LiveJournal::Comment
- Inherits:
-
Object
- Object
- LiveJournal::Comment
- Defined in:
- lib/livejournal/comment.rb,
lib/livejournal/database.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#commentid ⇒ Object
Returns the value of attribute commentid.
-
#itemid ⇒ Object
Returns the value of attribute itemid.
-
#parentid ⇒ Object
Returns the value of attribute parentid.
-
#posterid ⇒ Object
Returns the value of attribute posterid.
-
#state ⇒ Object
State of the comment.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#time ⇒ Object
a Ruby Time object.
Class Method Summary collapse
-
.state_from_string(str) ⇒ Object
Convert a state to the string representation used by LiveJournal.
-
.state_to_string(state) ⇒ Object
Convert a state from the string representation used by LiveJournal.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize ⇒ Comment
constructor
A new instance of Comment.
- #load_from_database_row(row) ⇒ Object
- #to_database_row ⇒ Object
Constructor Details
#initialize ⇒ Comment
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
#body ⇒ Object
Returns the value of attribute body.
34 35 36 |
# File 'lib/livejournal/comment.rb', line 34 def body @body end |
#commentid ⇒ Object
Returns the value of attribute commentid.
31 32 33 |
# File 'lib/livejournal/comment.rb', line 31 def commentid @commentid end |
#itemid ⇒ Object
Returns the value of attribute itemid.
31 32 33 |
# File 'lib/livejournal/comment.rb', line 31 def itemid @itemid end |
#parentid ⇒ Object
Returns the value of attribute parentid.
31 32 33 |
# File 'lib/livejournal/comment.rb', line 31 def parentid @parentid end |
#posterid ⇒ Object
Returns the value of attribute posterid.
31 32 33 |
# File 'lib/livejournal/comment.rb', line 31 def posterid @posterid end |
#state ⇒ Object
State of the comment. Possible values: :screened
, :deleted
33 34 35 |
# File 'lib/livejournal/comment.rb', line 33 def state @state end |
#subject ⇒ Object
Returns the value of attribute subject.
34 35 36 |
# File 'lib/livejournal/comment.rb', line 34 def subject @subject end |
#time ⇒ Object
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_row ⇒ Object
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 |