Class: Rubyhexagon::Pool
- Inherits:
-
Object
- Object
- Rubyhexagon::Pool
- Defined in:
- lib/rubyhexagon/pool.rb,
lib/rubyhexagon/api/pool.rb
Overview
A class to interact with the e621 web interface.
Instance Attribute Summary collapse
-
#created_at ⇒ Time
readonly
Returns creation time.
-
#creator ⇒ E621::User
readonly
Returns the user, who has created this pool.
-
#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.
-
#post_count ⇒ Integer
readonly
Returns number of posts inside pool.
-
#posts ⇒ Array<Post>
readonly
Returns an array of posts, that belong to this pool.
-
#updated_at ⇒ Time
readonly
Returns time of last update.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ TrueClass, FalseClass
Comparison method for Pool objects.
-
#active? ⇒ TrueClass, FalseClass
Returns active status.
-
#initialize(pool) ⇒ Object
constructor
Initializer for Pool objects.
-
#locked? ⇒ TrueClass, FalseClass
Returns locking status.
- #show(page) ⇒ Object
Constructor Details
#initialize(pool) ⇒ Object
Initializer for Pool objects
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rubyhexagon/pool.rb', line 57 def initialize(pool) raise ArgumentError, "#{pool.class} is not a Hash" unless pool.is_a?(Hash) raise ArgumentError, 'Hash must include :id' if pool[:id].nil? pool.each do |k, v| if %i[id name post_count is_active is_locked description].include?(k) if k == :id && !(v.is_a?(Integer) && v.positive?) raise InvalidIDError, "ID out of range: #{v}" end instance_variable_set("@#{k}".to_sym, v) elsif %i[updated_at created_at].include?(k) instance_variable_set("@#{k}".to_sym, Time.at(v[:s])) elsif k == :user_id @creator = E621::User.new(id: v) elsif k == :posts @posts = v.map { |post| E621::Post.new(post) } end end 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 |
#creator ⇒ E621::User (readonly)
Returns the user, who has created this pool
45 46 47 |
# File 'lib/rubyhexagon/pool.rb', line 45 def creator @creator 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 |
#post_count ⇒ Integer (readonly)
Returns number of posts inside pool
42 43 44 |
# File 'lib/rubyhexagon/pool.rb', line 42 def post_count @post_count end |
#posts ⇒ Array<Post> (readonly)
Returns an array of posts, that belong to this pool
48 49 50 |
# File 'lib/rubyhexagon/pool.rb', line 48 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 |
Class Method Details
.list(query) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/rubyhexagon/api/pool.rb', line 37 def self.list(query) raise ArgumentError, 'A Hash is required' unless query.is_a?(Hash) E621::API.fetch(:pool, :index, query).map do |pool| new(pool) end end |
.show(pool, page = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubyhexagon/api/pool.rb', line 25 def self.show(pool, page = nil) unless (pool.is_a?(Hash) && pool[:id].is_a?(Integer)) || pool.is_a?(E621::Pool) raise ArgumentError, 'A Hash or pool object are required' end id = pool.is_a?(Hash) ? pool[:id] : pool.id page = page.nil? ? pool[:page] : page[:page] E621::API.fetch(:pool, :show, id: id, page: page)[:posts].map do |post| E621::Post.new(post) end end |
Instance Method Details
#==(other) ⇒ TrueClass, FalseClass
Comparison method for Pool objects
101 102 103 |
# File 'lib/rubyhexagon/pool.rb', line 101 def ==(other) other.is_a?(Pool) && @id == other.id && @updated_at == other.updated_at end |
#active? ⇒ TrueClass, FalseClass
Returns active status
90 91 92 |
# File 'lib/rubyhexagon/pool.rb', line 90 def active? @is_active end |
#locked? ⇒ TrueClass, FalseClass
Returns locking status
81 82 83 |
# File 'lib/rubyhexagon/pool.rb', line 81 def locked? @is_locked end |