Class: Chico::Extractor
- Inherits:
-
Object
- Object
- Chico::Extractor
- Defined in:
- lib/chico/extractor.rb
Overview
Extracts icons images (bmp / png) from an .ico file
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #image_for(entry) ⇒ Object
-
#image_sizes ⇒ Object
Returns the sizes of the images packed in this icon, as width, height pairs, sorted from smallest to largest width.
-
#initialize(bin) ⇒ Extractor
constructor
A new instance of Extractor.
- #largest ⇒ Object
-
#method_missing(sym, *args, &block) ⇒ Object
Add support for retrieving images by their size, e.g.
- #num_images ⇒ Object
- #smallest ⇒ Object
Constructor Details
#initialize(bin) ⇒ Extractor
Returns a new instance of Extractor.
7 8 9 10 11 |
# File 'lib/chico/extractor.rb', line 7 def initialize(bin) @sio = StringIO.new(bin, 'rb') @entries = [] parse_icondir end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
Add support for retrieving images by their size, e.g. 32x32, 16x16, etc.
24 25 26 27 28 29 30 |
# File 'lib/chico/extractor.rb', line 24 def method_missing(sym, *args, &block) if sym.to_s =~ /^(\d+)x(\d+)$/ image_by_size $1, $2 else super end end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
5 6 7 |
# File 'lib/chico/extractor.rb', line 5 def entries @entries end |
Instance Method Details
#image_for(entry) ⇒ Object
42 43 44 |
# File 'lib/chico/extractor.rb', line 42 def image_for(entry) extract_image(entry) end |
#image_sizes ⇒ Object
Returns the sizes of the images packed in this icon, as width, height pairs, sorted from smallest to largest width
19 20 21 |
# File 'lib/chico/extractor.rb', line 19 def image_sizes @entries.map {|e| [e[:width], e[:height]] }.sort end |
#largest ⇒ Object
32 33 34 35 |
# File 'lib/chico/extractor.rb', line 32 def largest w, h = image_sizes.last self.send "#{w}x#{h}".to_sym end |
#num_images ⇒ Object
13 14 15 |
# File 'lib/chico/extractor.rb', line 13 def num_images @entries.size end |
#smallest ⇒ Object
37 38 39 40 |
# File 'lib/chico/extractor.rb', line 37 def smallest w, h = image_sizes.first self.send "#{w}x#{h}".to_sym end |