Class: RsrGroup::ResponseFile
- Defined in:
- lib/rsr_group/response_file.rb
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
Instance Attribute Summary collapse
-
#content ⇒ Object
(also: #get_content)
Returns the value of attribute content.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#mtime ⇒ Object
Returns the value of attribute mtime.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ResponseFile
constructor
A new instance of ResponseFile.
- #response_type ⇒ Object
- #to_json ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ ResponseFile
Returns a new instance of ResponseFile.
7 8 9 10 11 12 13 |
# File 'lib/rsr_group/response_file.rb', line 7 def initialize( = {}) requires!(, :username, :password, :filename) @credentials = .select { |k, v| [:username, :password].include?(k) } @filename = File.basename([:filename]) @account_number = @filename.split('-')[2] end |
Instance Attribute Details
#content ⇒ Object Also known as: get_content
Returns the value of attribute content.
5 6 7 |
# File 'lib/rsr_group/response_file.rb', line 5 def content @content end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/rsr_group/response_file.rb', line 4 def filename @filename end |
#mtime ⇒ Object
Returns the value of attribute mtime.
5 6 7 |
# File 'lib/rsr_group/response_file.rb', line 5 def mtime @mtime end |
Class Method Details
.all(options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rsr_group/response_file.rb', line 41 def self.all( = {}) requires!(, :username, :password) Base.connect() do |ftp| ftp.chdir(RsrGroup.config.response_dir) @resp = ftp.nlst("*.txt") ftp.close end @resp end |
.get_each(options = {}, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rsr_group/response_file.rb', line 21 def self.get_each( = {}, &block) requires!(, :username, :password) Base.connect() do |ftp| ftp.chdir(RsrGroup.config.response_dir) @list = ftp.nlst("*.txt") @list.each do |file| resource = new(.merge(filename: file)) resource.content = ftp.gettextfile(file, nil) resource.mtime = ftp.mtime(file) yield(resource) end ftp.close end @list end |
Instance Method Details
#response_type ⇒ Object
64 65 66 |
# File 'lib/rsr_group/response_file.rb', line 64 def response_type FILE_TYPES[@filename.split("-").first] end |
#to_json ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rsr_group/response_file.rb', line 68 def to_json get_content if @content.length == 0 raise ZeroByteFile.new("File is empty (filename: #{@filename})") end @json = { response_type: response_type, filename: @filename, account_number: @account_number, rsr_order_number: nil, details: [], errors: [], } return parse_eerr if error? return parse_econf if confirmation? return parse_eship if shipping? end |