Class: E621::Post
Instance Method Summary collapse
-
#initialize(post) ⇒ Post
(also: #show)
constructor
A new instance of Post.
-
#vote(direction) ⇒ Object
Cast a vote! Any value above 0 votes up, every value below 0 votes down.
Methods inherited from Container
Constructor Details
#initialize(post) ⇒ Post Also known as: show
Returns a new instance of Post.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/post.rb', line 24 def initialize(post) @api = API.new if post.is_a?(Fixnum) || (post.is_a?(String) && post.match(/^[0-9,a-f]+$/i)) then post = if post.is_a?(String) && post.length == 32 then {md5:post} elsif post.is_a?(Fixnum) || (post.is_a?(String) && post.match(/^\d+$/)) then {id:post.to_i} else raise ArgumentError, "Neither an ID nor a MD5 Hash." end post = @api.post_show(post) elsif post.is_a?(Hash) then # Variable post is ready to use. Do nothing. else raise ArgumentError, "Post only accepts an id, a MD5 hashsum or a Ruby hash." end set_variables(post) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class E621::Container
Instance Method Details
#vote(direction) ⇒ Object
Cast a vote! Any value above 0 votes up, every value below 0 votes down. Zero itself causes an error.
43 44 45 46 47 48 |
# File 'lib/post.rb', line 43 def vote(direction) if direction > 0 then @api.post_vote(1) elsif direction < 0 then @api.post_vote(-1) else raise ArgumentError, "Zero isn't allowed for voting results." end end |