Class: Presdocs::Category
- Inherits:
-
Object
- Object
- Presdocs::Category
- Defined in:
- lib/presdocs/category.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Category
constructor
A new instance of Category.
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
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'lib/presdocs/category.rb', line 4 def children @children end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
4 5 6 |
# File 'lib/presdocs/category.rb', line 4 def count @count end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/presdocs/category.rb', line 4 def name @name end |
Class Method Details
.all ⇒ Object
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 |