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
28
29
30
31
32
33
# File 'lib/pool.rb', line 24

def initialize(post)
  @api = API.new("pool")
  if post.is_a?(Hash) then
    set_variables(post)
  elsif post.is_a?(Fixnum) then
    set_variables(@api.get("show",{"id"=>post}))
  else
    raise ArgumentError, "Parameter must be Hash or Number."
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class E621::Container

Instance Method Details

#each_postObject



61
62
63
64
65
66
67
68
69
# File 'lib/pool.rb', line 61

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



35
36
37
# File 'lib/pool.rb', line 35

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

#name=(name) ⇒ Object



43
44
45
# File 'lib/pool.rb', line 43

def name=(name)
  @name = name
end

#posts=(posts) ⇒ Object



47
48
49
# File 'lib/pool.rb', line 47

def posts=(posts)
  @posts = posts
end

#to_json(n = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/pool.rb', line 51

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



39
40
41
# File 'lib/pool.rb', line 39

def updated_at=(time)
  @updated_at = time
end