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 = {}) ⇒ Object



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

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

Instance Method Details

#allObject



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

def all
  tempfile = get_file(CATALOG_FILENAME)
  items = []

  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

    _map_hash = map_hash(Nokogiri::XML::DocumentFragment.parse(node.inner_xml))

    items << _map_hash unless _map_hash.nil?
  end

  tempfile.close
  tempfile.unlink

  items
end