Class: Presdocs::Category

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Category

Returns a new instance of Category.



6
7
8
9
10
# File 'lib/presdocs/category.rb', line 6

def initialize(params={})
  params.each_pair do |k,v|
   instance_variable_set("@#{k}", v)
  end
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



4
5
6
# File 'lib/presdocs/category.rb', line 4

def children
  @children
end

#countObject (readonly)

Returns the value of attribute count.



4
5
6
# File 'lib/presdocs/category.rb', line 4

def count
  @count
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/presdocs/category.rb', line 4

def name
  @name
end

Class Method Details

.allObject



12
13
14
15
16
# File 'lib/presdocs/category.rb', line 12

def self.all
  url = "http://m.gpo.gov/wscpd/mobilecpd/category.json"
  results = Oj.load(open(url).read)
  create_categories(results['navigatorResults']['Category'])
end

.create_categories(results) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/presdocs/category.rb', line 18

def self.create_categories(results)
  cats = []
  results.each do |result|
    cats << self.new(:name => result['name'],
              :count => result['count'],
              :children => result['children'])
  end
  cats
end