Class: E621::Post
- Inherits:
-
Object
- Object
- E621::Post
- Defined in:
- lib/rubyhexagon/post.rb
Overview
This class holds post information, fetched from e621, and gives access in a more Ruby like manner.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#artists ⇒ Array<Artist>
readonly
Array of artists, that work on the image in this post.
-
#author ⇒ User
readonly
User object of who uploaded this post.
-
#children ⇒ Array<Post>
readonly
Array of child posts.
-
#created_at ⇒ Time
readonly
Creation time of post.
-
#description ⇒ String
readonly
Description that's associated with this post.
-
#favorites ⇒ Integer
readonly
Number of people, who favorited this post.
-
#id ⇒ Integer
readonly
Id of post information.
-
#image ⇒ E621::Image
readonly
File content of this post.
-
#md5 ⇒ String
readonly
MD5 checksum associated with this post.
- #parent ⇒ Post, NilClass readonly
-
#preview ⇒ E621::Preview
readonly
Preview data in E621::Preview format.
-
#rating ⇒ Symbol
readonly
Rating of this post.
-
#sample ⇒ E621::Sample
readonly
Sample data in E621::Sample format.
-
#score ⇒ Integer
readonly
Vote score this post holds.
-
#sources ⇒ Array<String>
readonly
Array of sources.
-
#status ⇒ Symbol
readonly
Status of post, can be :active, :flagged, :pending or :deleted.
-
#tag_names ⇒ Array<String>
readonly
Tag names only for convenience.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for posts.
-
#initialize(id) ⇒ Object
constructor
Initializer for Post.
-
#show(post = nil) ⇒ Object
Fetch data from e621 to current post id.
-
#show!(post = nil) ⇒ Object
Fetch data from e621 to current post id.
-
#tags ⇒ Array<Tag>
Retrieve an Array of this post's tags.
-
#test(test_var = nil) ⇒ TrueClass, FalseClass
(also: #active?, #flagged?, #pending?, #deleted?, #safe?, #questionable?, #explicit?)
Test status with an optional parameter.
Constructor Details
#initialize(id) ⇒ Object
Initializer for Post.
87 88 89 90 91 92 93 |
# File 'lib/rubyhexagon/post.rb', line 87 def initialize(id) id = id.to_i unless id.is_a?(Integer) && id > 0 raise InvalidIDError, "ID out of range: #{id}" end @id = id end |
Instance Attribute Details
#artists ⇒ Array<Artist> (readonly)
Returns array of artists, that work on the image in this post.
43 44 45 |
# File 'lib/rubyhexagon/post.rb', line 43 def artists @artists end |
#author ⇒ User (readonly)
Returns user object of who uploaded this post.
28 29 30 |
# File 'lib/rubyhexagon/post.rb', line 28 def @author end |
#children ⇒ Array<Post> (readonly)
Returns Array of child posts.
63 64 65 |
# File 'lib/rubyhexagon/post.rb', line 63 def children @children end |
#created_at ⇒ Time (readonly)
Returns creation time of post.
31 32 33 |
# File 'lib/rubyhexagon/post.rb', line 31 def created_at @created_at end |
#description ⇒ String (readonly)
Returns description that's associated with this post.
46 47 48 |
# File 'lib/rubyhexagon/post.rb', line 46 def description @description end |
#favorites ⇒ Integer (readonly)
Returns number of people, who favorited this post.
49 50 51 |
# File 'lib/rubyhexagon/post.rb', line 49 def favorites @favorites end |
#id ⇒ Integer (readonly)
Returns id of post information.
25 26 27 |
# File 'lib/rubyhexagon/post.rb', line 25 def id @id end |
#image ⇒ E621::Image (readonly)
Returns file content of this post.
69 70 71 |
# File 'lib/rubyhexagon/post.rb', line 69 def image @image end |
#md5 ⇒ String (readonly)
Returns MD5 checksum associated with this post.
66 67 68 |
# File 'lib/rubyhexagon/post.rb', line 66 def md5 @md5 end |
#parent ⇒ Post, NilClass (readonly)
60 61 62 |
# File 'lib/rubyhexagon/post.rb', line 60 def parent @parent end |
#preview ⇒ E621::Preview (readonly)
Returns preview data in E621::Preview format.
75 76 77 |
# File 'lib/rubyhexagon/post.rb', line 75 def preview @preview end |
#rating ⇒ Symbol (readonly)
Returns rating of this post. Can be one of :safe, :questionable, :explicit.
56 57 58 |
# File 'lib/rubyhexagon/post.rb', line 56 def @rating end |
#sample ⇒ E621::Sample (readonly)
Returns sample data in E621::Sample format.
72 73 74 |
# File 'lib/rubyhexagon/post.rb', line 72 def sample @sample end |
#score ⇒ Integer (readonly)
Returns vote score this post holds.
52 53 54 |
# File 'lib/rubyhexagon/post.rb', line 52 def score @score end |
#sources ⇒ Array<String> (readonly)
Returns array of sources. This can contain URI in string form.
39 40 41 |
# File 'lib/rubyhexagon/post.rb', line 39 def sources @sources end |
#status ⇒ Symbol (readonly)
Returns status of post, can be :active, :flagged, :pending or :deleted.
35 36 37 |
# File 'lib/rubyhexagon/post.rb', line 35 def status @status end |
#tag_names ⇒ Array<String> (readonly)
Returns tag names only for convenience.
78 79 80 |
# File 'lib/rubyhexagon/post.rb', line 78 def tag_names @tag_names end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparison method for posts
160 161 162 |
# File 'lib/rubyhexagon/post.rb', line 160 def ==(other) other.is_a?(Post) && @id == other.id end |
#show(post = nil) ⇒ Object
Fetch data from e621 to current post id
115 116 117 118 119 120 |
# File 'lib/rubyhexagon/post.rb', line 115 def show(post = nil) post = API.new.fetch('post', 'show', id: @id) if post.nil? tmp = Post.new(post[:id].to_i) tmp.show!(post) tmp end |
#show!(post = nil) ⇒ Object
Fetch data from e621 to current post id
100 101 102 103 104 105 106 107 108 |
# File 'lib/rubyhexagon/post.rb', line 100 def show!(post = nil) post = API.new.fetch('post', 'show', id: @id) if post.nil? @created_at = Time.at(post[:created_at][:s].to_i) @status = post[:status].to_sym (post) setup_relatives(post) setup_file_data(post) setup_additional_data(post) end |
#tags ⇒ Array<Tag>
Retrieve an Array of this post's tags
127 128 129 130 131 |
# File 'lib/rubyhexagon/post.rb', line 127 def API.new.fetch('post', 'tags', id: @id).map do |tag| Tag.new(tag[:id]).show(tag) end end |
#test(test_var = nil) ⇒ TrueClass, FalseClass Also known as: active?, flagged?, pending?, deleted?, safe?, questionable?, explicit?
Test status with an optional parameter. This is more meant to be used by alias methods
142 143 144 145 146 |
# File 'lib/rubyhexagon/post.rb', line 142 def test(test_var = nil) test_var ||= __callee__.to_s.sub(/\?/, '').to_sym test_ar = %i[safe questionable explicit] test_ar.include?(test_var) ? @rating == test_var : @status == test_var end |