Class: Bin2Hex::BinaryToHexFileConverter

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BinaryToHexFileConverter

Returns a new instance of BinaryToHexFileConverter.



4
5
6
# File 'lib/bin2hex.rb', line 4

def initialize(options)
  @options = options
end

Instance Method Details

#process_file(input, output) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bin2hex.rb', line 8

def process_file(input, output)
  begin
    File.open(sprintf(output, input), "w") do |out_file|
      File.open(input, "rb").each_byte do |b|
        out_file.write(sprintf(@options[:format], b))
      end
    end
  rescue Errno::ENOENT => e
    puts "Error: #{e.message}"
  end
end