Class: E621::Pool

Inherits:
Container show all
Defined in:
lib/pool.rb

Instance Method Summary collapse

Methods inherited from Container

#method_missing

Constructor Details

#initialize(post) ⇒ Pool

Returns a new instance of Pool.



24
25
26
27
# File 'lib/pool.rb', line 24

def initialize(post)
  @api = API.new("pool")
  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

#each_postObject



55
56
57
58
59
60
61
62
63
# File 'lib/pool.rb', line 55

def each_post
  (@post_count/24.0).ceil.times do |page|
    @posts.each do |post|
      yield post
    end
    post = api.get("show",{"id"=>@id,"page"=>page+2})
    set_variables(post)
  end
end

#keysObject



29
30
31
# File 'lib/pool.rb', line 29

def keys
  return instance_variables.map{|i|i.to_s.sub("@","")}
end

#name=(name) ⇒ Object



37
38
39
# File 'lib/pool.rb', line 37

def name=(name)
  @name = name
end

#posts=(posts) ⇒ Object



41
42
43
# File 'lib/pool.rb', line 41

def posts=(posts)
  @posts = posts
end

#to_json(n = nil) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/pool.rb', line 45

def to_json(n=nil)
  json_hash = Hash.new
  instance_variables.each do |i|
    v = instance_variable_get(i)
    v = v.is_a?(Time) ? v.to_i : v
    json_hash.store(i.to_s.sub("@",""),v)
  end
  return json_hash.to_json
end

#updated_at=(time) ⇒ Object



33
34
35
# File 'lib/pool.rb', line 33

def updated_at=(time)
  @updated_at = time
end