Class: RsrGroup::Catalog
Constant Summary
Constants inherited from Base
Base::DEFAULT_CATALOG_FILENAME, Base::DEFAULT_DIR, Base::KEYDEALER_CATALOG_FILENAME, Base::KEYDEALER_DIR, Base::MAP_FILENAME, Base::QTY_FILENAME
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
-
#initialize(options = {}) ⇒ Catalog
constructor
A new instance of Catalog.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Catalog
Returns a new instance of Catalog.
4 5 6 7 |
# File 'lib/rsr_group/catalog.rb', line 4 def initialize( = {}) requires!(, :username, :password) @options = end |
Class Method Details
.all(options = {}) ⇒ Object
9 10 11 12 |
# File 'lib/rsr_group/catalog.rb', line 9 def self.all( = {}) requires!(, :username, :password) new().all end |
Instance Method Details
#all ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rsr_group/catalog.rb', line 14 def all items = [] connect(@options) do |ftp| begin tempfile = Tempfile.new if ftp.nlst.include?(KEYDEALER_DIR) ftp.chdir(KEYDEALER_DIR) ftp.getbinaryfile(KEYDEALER_CATALOG_FILENAME, tempfile.path) else ftp.chdir(DEFAULT_DIR) ftp.getbinaryfile(DEFAULT_CATALOG_FILENAME, tempfile.path) end ftp.close CSV.foreach(tempfile, { col_sep: ';', quote_char: "\x00" }).each do |row| item = process_row(row) if !row[12].nil? && row[12].to_sym.eql?(:Allocated) item[:quantity] = 0 end items << item end end tempfile.unlink end items end |