Module: VastApi::Categories::Category

Defined in:
lib/vast_api/categories/category.rb

Instance Method Summary collapse

Instance Method Details

#categoriesObject

Convert a selected node to a Hash. It accepts a CSS3 Selector as an attribute. Returns the hash.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vast_api/categories/category.rb', line 6

def categories
  if self['id']
    hash = {}
    self.element_children.each do |node|
      node.extend(Category)
      hash[node['id']] = {
        :name => node['name'],
        :count => node['count']
      }
      if self.element_children.length > 0
        cats = node.categories
        hash[node['id']][:children] = cats unless cats.empty?
      end
    end
    # Return the hash
    hash
  end
end