Class: Grin::Category

Inherits:
Client
  • Object
show all
Defined in:
lib/grin/category.rb

Constant Summary

Constants inherited from Client

Grin::Client::API_VERSION, Grin::Client::DOMAIN

Instance Method Summary collapse

Methods inherited from Client

#album, #categories, #category, #create_album, #create_category, #find_or_create_album, #find_or_create_category

Constructor Details

#initialize(data) ⇒ Category

Returns a new instance of Category.



4
5
6
7
8
9
10
11
# File 'lib/grin/category.rb', line 4

def initialize(data)
  data.each do |key, value|
    instance_variable_set("@#{key}", value)
    Category.instance_eval do
      attr_reader key.to_sym
    end
  end
end

Instance Method Details

#albumsObject



13
14
15
16
17
# File 'lib/grin/category.rb', line 13

def albums
  albums = []
  get('albums.json').select { |album| album['category']['id'] == id  }.each { |album| albums << Album.new(album) }
  return albums
end

#destroyObject



19
20
21
# File 'lib/grin/category.rb', line 19

def destroy
  delete("categories/#{id}.json")
end