Class: MgeWholesale::Catalog

Inherits:
Base
  • Object
show all
Defined in:
lib/mge_wholesale/catalog.rb

Constant Summary collapse

CATALOG_FILENAME =
'vendorname_items.xml'
ITEM_NODE_NAME =
'item'
PERMITTED_FEATURES =
[
  'Action',
  'Barrel_Length',
  'Blade_Edge',
  'Blade_Finish',
  'Blade_Length',
  'Blade_Style',
  'Box_Qty',
  'Bullet_Type',
  'Caliber',
  'Caliber_Gauge',
  'Capacity',
  'Carry_Type',
  'Color',
  'Cutting_Edge',
  'Diameter',
  'Edge',
  'Finish',
  'Gauge',
  'Grain',
  'Grit',
  'Gun_Manufacturer',
  'Gun_Model',
  'L_x_W',
  'Magnifactaion',
  'Material',
  'Model',
  'OAL',
  'Reticle',
  'Shell_Length',
  'Shot',
  'Tube_Diameter',
  'Type'
]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

connect

Constructor Details

#initialize(options = {}) ⇒ Catalog

Returns a new instance of Catalog.



42
43
44
45
# File 'lib/mge_wholesale/catalog.rb', line 42

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

Class Method Details

.all(options = {}, &block) ⇒ Object



47
48
49
50
# File 'lib/mge_wholesale/catalog.rb', line 47

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

Instance Method Details

#all(&block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/mge_wholesale/catalog.rb', line 52

def all(&block)
  tempfile = get_file(CATALOG_FILENAME)

  Nokogiri::XML::Reader.from_io(tempfile).each do |node|
    next unless node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
    next unless node.name == ITEM_NODE_NAME

    yield map_hash(Nokogiri::XML::DocumentFragment.parse(node.inner_xml))
  end

  tempfile.close
  tempfile.unlink
end