Module: Chico

Defined in:
lib/chico/bitmapper.rb,
lib/chico.rb,
lib/chico/fetcher.rb,
lib/chico/extractor.rb

Overview

Unpack an ico bitmap

Defined Under Namespace

Classes: Bitmapper, Extractor, Fetcher

Class Method Summary collapse

Class Method Details

.extract_from_file(filepath, dest_dir, options = {}) ⇒ Object



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

def self.extract_from_file(filepath, dest_dir, options={})
  ex = Extractor.new(IO.read(filepath))
  basename = File.basename(filepath, File.extname(filepath))
  ex.entries.each do |entry|
    ext = "#{entry[:width]}x#{entry[:height]}"
    content = ex.image_for(entry)
    File.open(File.join(dest_dir, "#{basename}.#{ext}.png"), 'wb') do |f|
      f.write content
    end
  end
end

.extract_from_url(url, dest_dir, options = {}) ⇒ Object



20
21
22
23
24
# File 'lib/chico.rb', line 20

def self.extract_from_url(url, dest_dir, options={})
  fetcher = Fetecher.new(url)
  ex = Extractor.new(fetcher.fetch)
  write_to_files(ex, dest_dir, URI.parse(url).host)
end