class Ravelry::Category

There is no API access point for PatternCategories. The information used to create `Ravelry::Category` comes from {Ravelry::Pattern} objects.

You should not create `Category` objects manually; they are all created–and owned by–by a {Ravelry::Pattern}.

See {Ravelry::Pattern} for more information about `Pattern` objects.

This does not inherit from {Ravelry::Data} because it doesn't have a corresponding API endpoint.

Attributes

grandparent_name[R]
greatgrandparent_name[R]
name[R]
parent_name[R]

Public Class Methods

new(category) click to toggle source

Creates new `Category` from Ravelry API PatternCategories attributes up to the great grandparent level

All class variables are readonly.

# File lib/ravelry/category.rb, line 18
def initialize(category)
  @name = category[:name]
  @permalink = category[:permalink]
  @category = category
  set_relatives
end

Protected Instance Methods

grandparent() click to toggle source

Returns parent name and sets grandparent attributes from existing `data`.

# File lib/ravelry/category.rb, line 35
def grandparent
  if @category[:parent][:parent]
    @grandparent_permalink = @category[:parent][:parent][:permalink]
    @grandparent_name = @category[:parent][:parent][:name]
  end
end
greatgrandparent() click to toggle source

Returns parent name and sets greatgrandparent attributes from existing `data`.

# File lib/ravelry/category.rb, line 43
def greatgrandparent
  if @category[:parent][:parent][:parent]
    @greatgrandparent_permalink = @category[:parent][:parent][:parent][:permalink]
    @greatgrandparent_name = @category[:parent][:parent][:parent][:name]
  end
end
parent() click to toggle source

Returns parent name and sets parent attributes from existing `data`.

# File lib/ravelry/category.rb, line 27
def parent
  if @category[:parent]
    @parent_permalink = @category[:parent][:permalink]
    @parent_name = @category[:parent][:name]
  end
end

Private Instance Methods

set_relatives() click to toggle source
# File lib/ravelry/category.rb, line 51
def set_relatives
  parent if @category[:parent]
  grandparent if @category[:parent][:parent]
  greatgrandparent if @category[:parent][:parent][:parent]
end