Sha256: 8032ee949936a75b0dd753af47d0a885b8894680b977f3af5633460831eef76b

Contents?: true

Size: 956 Bytes

Versions: 59

Compression:

Stored size: 956 Bytes

Contents

module BillHicks
  # Category item response structure:
  #
  #   {
  #     code:        "...",  # ':category_code' in Catalog response.
  #     description: "..."   # ':category_description' in Catalog response.
  #   }
  class Category < Base

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

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

    # Returns an array of hashes with category details.
    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

  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
bill_hicks-2.0.7 lib/bill_hicks/category.rb
bill_hicks-2.0.6 lib/bill_hicks/category.rb
bill_hicks-2.0.5 lib/bill_hicks/category.rb
bill_hicks-2.0.4 lib/bill_hicks/category.rb
bill_hicks-2.0.3 lib/bill_hicks/category.rb
bill_hicks-2.0.2 lib/bill_hicks/category.rb
bill_hicks-1.3.6 lib/bill_hicks/category.rb
bill_hicks-2.0.1 lib/bill_hicks/category.rb
bill_hicks-2.0 lib/bill_hicks/category.rb
bill_hicks-1.3.5 lib/bill_hicks/category.rb
bill_hicks-1.3.4 lib/bill_hicks/category.rb
bill_hicks-1.3.3 lib/bill_hicks/category.rb
bill_hicks-1.3.2 lib/bill_hicks/category.rb
bill_hicks-1.3.1 lib/bill_hicks/category.rb
bill_hicks-1.3.0 lib/bill_hicks/category.rb
bill_hicks-1.2.4 lib/bill_hicks/category.rb
bill_hicks-1.2.3 lib/bill_hicks/category.rb
bill_hicks-1.2.2 lib/bill_hicks/category.rb
bill_hicks-1.2.1 lib/bill_hicks/category.rb
bill_hicks-1.2.1.pre lib/bill_hicks/category.rb