Class: MgeWholesale::Category
- Defined in:
- lib/mge_wholesale/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
-
#all(&block) ⇒ Object
Returns an array of hashes with category details.
-
#initialize(options = {}) ⇒ Category
constructor
A new instance of Category.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Category
Returns a new instance of Category.
10 11 12 13 |
# File 'lib/mge_wholesale/category.rb', line 10 def initialize( = {}) requires!(, :username, :password) = end |
Class Method Details
.all(options = {}, &block) ⇒ Object
15 16 17 18 |
# File 'lib/mge_wholesale/category.rb', line 15 def self.all( = {}, &block) requires!(, :username, :password) new().all(&block) end |
Instance Method Details
#all(&block) ⇒ Object
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 38 39 |
# File 'lib/mge_wholesale/category.rb', line 21 def all(&block) categories = [] # Categories are listed in catalog xml, so fetch that. catalog = Catalog.new() catalog.all do |item| categories << { code: item[:subcategory].gsub("&", "").gsub(/[^A-Za-z0-9]/, "_").squeeze("_").downcase, description: item[:subcategory].gsub("&", "&") } end categories.uniq! { |c| c[:code] } categories.sort_by! { |c| c[:code] } categories.each do |category| yield category end end |