Class: Rubyhexagon::Pool
- Inherits:
-
Object
- Object
- Rubyhexagon::Pool
- Defined in:
- lib/rubyhexagon/pool.rb
Overview
This class holds post information, fetched from e621, and gives access in a more Ruby like manner.
Instance Attribute Summary collapse
-
#created_at ⇒ Time
readonly
Returns creation time.
-
#description ⇒ String
readonly
Returns a description of the current pool.
-
#id ⇒ Integer
readonly
Returns this pool's ID.
-
#name ⇒ String
readonly
Returns name of current pool.
-
#posts ⇒ Array<Post>
readonly
Returns an array of posts, that belong to this pool.
-
#updated_at ⇒ Time
readonly
Returns time of last update.
-
#user ⇒ User
readonly
Returns the user, who has created this pool.
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for Pool objects.
-
#active? ⇒ TrueClass, FalseClass
Returns active status.
-
#initialize(id) ⇒ Object
constructor
Initializer for Pool objects.
-
#locked? ⇒ TrueClass, FalseClass
Returns locking status.
-
#show(pool = nil) ⇒ Object
Fetch data from e621 to current pool id.
-
#show!(pool = nil) ⇒ Object
Fetch data from e621 to current post id.
Constructor Details
#initialize(id) ⇒ Object
Initializer for Pool objects
54 55 56 57 58 59 |
# File 'lib/rubyhexagon/pool.rb', line 54 def initialize(id) unless id.is_a?(Integer) && id.positive? raise InvalidIDError, "ID out of range: #{id}" end @id = id end |
Instance Attribute Details
#created_at ⇒ Time (readonly)
Returns creation time
33 34 35 |
# File 'lib/rubyhexagon/pool.rb', line 33 def created_at @created_at end |
#description ⇒ String (readonly)
Returns a description of the current pool
39 40 41 |
# File 'lib/rubyhexagon/pool.rb', line 39 def description @description end |
#id ⇒ Integer (readonly)
Returns this pool's ID
27 28 29 |
# File 'lib/rubyhexagon/pool.rb', line 27 def id @id end |
#name ⇒ String (readonly)
Returns name of current pool
30 31 32 |
# File 'lib/rubyhexagon/pool.rb', line 30 def name @name end |
#posts ⇒ Array<Post> (readonly)
Returns an array of posts, that belong to this pool
45 46 47 |
# File 'lib/rubyhexagon/pool.rb', line 45 def posts @posts end |
#updated_at ⇒ Time (readonly)
Returns time of last update
36 37 38 |
# File 'lib/rubyhexagon/pool.rb', line 36 def updated_at @updated_at end |
#user ⇒ User (readonly)
Returns the user, who has created this pool
42 43 44 |
# File 'lib/rubyhexagon/pool.rb', line 42 def user @user end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparison method for Pool objects
124 125 126 127 128 129 130 131 |
# File 'lib/rubyhexagon/pool.rb', line 124 def ==(other) if @name.nil? other.is_a?(Pool) && @id == other.id else other.is_a?(Pool) && @name == other.name && @id == other.id && @updated_at == other.updated_at end end |
#active? ⇒ TrueClass, FalseClass
Returns active status
113 114 115 |
# File 'lib/rubyhexagon/pool.rb', line 113 def active? @is_active end |
#locked? ⇒ TrueClass, FalseClass
Returns locking status
104 105 106 |
# File 'lib/rubyhexagon/pool.rb', line 104 def locked? @is_locked end |
#show(pool = nil) ⇒ Object
Fetch data from e621 to current pool id
93 94 95 96 97 |
# File 'lib/rubyhexagon/pool.rb', line 93 def show(pool = nil) tmp = Pool.new(@id) tmp.show!(pool) tmp end |
#show!(pool = nil) ⇒ Object
Fetch data from e621 to current post id
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rubyhexagon/pool.rb', line 66 def show!(pool = nil) @posts = [] if pool.nil? page = 1 loop do pool = API.new.fetch('pool', 'show', id: @id, page: page) page += 1 @posts += pool[:posts].map do |post| E621::Post.new(post[:id]).show(post) end break if pool[:posts] == [] end end @name = pool[:name] @created_at = Time.at(pool[:created_at][:s].to_i) @updated_at = Time.at(pool[:updated_at][:s].to_i) @description = pool[:description] @user = User.new(id: pool[:user_id]) @is_locked = pool[:is_locked] @is_active = pool[:is_active] end |