Class: Raccdoc::Post
- Inherits:
-
Object
- Object
- Raccdoc::Post
- Defined in:
- lib/raccdoc/post.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#authority ⇒ Object
readonly
Returns the value of attribute authority.
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#delete ⇒ Object
Attempts to delete the current post.
-
#delete? ⇒ Boolean
Checks to see if the currently-logged-in user has permission to delete the current post.
-
#initialize(socket, postid, args = {}) ⇒ Post
constructor
Creates a new Raccdoc::Post object by reading the specified post.
Constructor Details
#initialize(socket, postid, args = {}) ⇒ Post
Creates a new Raccdoc::Post object by reading the specified post. If no post is given, it returns the first unread post, if any.
Useful information returned:
-
id - The numerical post ID
-
date - The date the post was made (or the current date in UTC if the post is anonymous)
-
author - The username of the user that created the post
-
body - The textual body of the post.
-
authority - either “Sysop” or “Forum Moderator” if the post was made with that header.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/raccdoc/post.rb', line 19 def initialize(socket,postid,args={}) @socket = socket dammit = args[:dammit] ? 'DAMMIT' : '' @socket.puts "READ #{postid.to_s} #{dammit}" response = @socket.readline.chomp unless response.match(/^3/) raise ResponseError, response end # Get header information post = Hash.new while line = @socket.readline.chomp break if line.match(/^$/) (key,value) = line.split(/: /) post[key.downcase.to_sym] = value end post[:id] = postid post[:date] = post[:date] ? Time.parse(post[:date]) : Time.new.getgm post[:body] = "" while (line = @socket.readline) break if line.match(/^\.$/) post[:body] << line end @id = post[:id] @date = post[:date] @author = post[:from] @body = post[:body] @authority = post[:authority] return post end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
6 7 8 |
# File 'lib/raccdoc/post.rb', line 6 def @author end |
#authority ⇒ Object (readonly)
Returns the value of attribute authority.
8 9 10 |
# File 'lib/raccdoc/post.rb', line 8 def @authority end |
#body ⇒ Object (readonly)
Returns the value of attribute body.
7 8 9 |
# File 'lib/raccdoc/post.rb', line 7 def body @body end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
5 6 7 |
# File 'lib/raccdoc/post.rb', line 5 def date @date end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/raccdoc/post.rb', line 4 def id @id end |
Instance Method Details
#delete ⇒ Object
Attempts to delete the current post.
Returns true or false
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/raccdoc/post.rb', line 71 def delete @socket.puts("DELETE NOTE #{self.id}") response = @socket.readline.chomp if response.match(/^2/) return true elsif response.match(/^4/) return false else raise ResponseError, response end end |
#delete? ⇒ Boolean
Checks to see if the currently-logged-in user has permission to delete the current post.
Returns true or false
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/raccdoc/post.rb', line 56 def delete? @socket.puts("OKAY DELETE NOTE #{self.id}") response = @socket.readline.chomp if response.match(/^2/) return true elsif response.match(/^4/) return false else raise ResponseError, response end end |