Class: E621::Set

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

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 = API.new("set")
  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_postObject



53
54
55
56
57
# File 'lib/set.rb', line 53

def each_post
  @posts.each do |post|
    yield post
  end
end

#keysObject



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_jsonObject



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