Class: E621::Set
Instance Method Summary
collapse
Methods inherited from Container
#method_missing
Constructor Details
#initialize(post) ⇒ Set
Returns a new instance of Set.
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/set.rb', line 22
def initialize(post)
@api,@page = API.new("set"),1
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
#add_post(id) ⇒ Object
33
34
35
|
# File 'lib/set.rb', line 33
def add_post(id)
@api.post("add_post",{"post_id"=>id,"set_id"=>@id})
end
|
#each_post ⇒ Object
53
54
55
56
57
|
# File 'lib/set.rb', line 53
def each_post
@posts.each do |post|
yield post
end
end
|
#keys ⇒ Object
37
38
39
|
# File 'lib/set.rb', line 37
def keys
return instance_variables.map{|i|i.to_s.sub("@","")}
end
|
#name=(name) ⇒ Object
41
42
43
|
# File 'lib/set.rb', line 41
def name=(name)
@name = name
end
|
#to_json ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/set.rb', line 45
def to_json
json_hash = Hash.new
instance_variables.each do |i|
json_hash.store(i.to_s.sub("@",""),instance_variable_get(i))
end
return json_hash.to_json
end
|