Class: Bestchange::ZipBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/bestchange/zip_builder.rb

Constant Summary collapse

ARCHIVE_DATA_ENCODING =
'ASCII-8BIT'

Instance Method Summary collapse

Constructor Details

#initialize(response_body) ⇒ ZipBuilder

Returns a new instance of ZipBuilder.



7
8
9
# File 'lib/bestchange/zip_builder.rb', line 7

def initialize(response_body)
  @response_body = response_body
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bestchange/zip_builder.rb', line 11

def call
  zip_file = Tempfile.new('', encoding: ARCHIVE_DATA_ENCODING)
  zip_file.write(@response_body)
  zip_file.rewind

  if block_given?
    begin
      yield zip_file
    ensure
      zip_file.close
    end
  else
    zip_file
  end
end