Class: BillHicks::Category

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

Overview

Category item response structure:

{
  code:        "...",  # ':category_code' in Catalog response.
  description: "..."   # ':category_description' in Catalog response.
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect

Constructor Details

#initialize(options = {}) ⇒ Category

Returns a new instance of Category.



10
11
12
13
# File 'lib/bill_hicks/category.rb', line 10

def initialize(options = {})
  requires!(options, :username, :password)
  @options = options
end

Class Method Details

.all(options = {}) ⇒ Object



15
16
17
18
# File 'lib/bill_hicks/category.rb', line 15

def self.all(options = {})
  requires!(options, :username, :password)
  new(options).all
end

Instance Method Details

#allObject

Returns an array of hashes with category details.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bill_hicks/category.rb', line 21

def all
  categories = []

  # Categories are listed in catalog csv, so fetch that.
  catalog = Catalog.all(@options)
  catalog.each do |item|
    categories << {
      code: item[:category_code],
      description: item[:category_description]
    }
  end

  categories.uniq! { |c| c[:description] }
  categories.sort_by! { |c| c[:description] }

  categories
end