Class: Crest::Photo
- Inherits:
-
Object
- Object
- Crest::Photo
- Defined in:
- lib/crest/photo.rb
Overview
The picture a card carries: bytes as they were handed over, or the file a path names.
Constant Summary collapse
- SIGNATURES =
The first bytes of each image format a phone will read a saved card's picture from.
{ 'PNG' => "\x89PNG".b, 'JPEG' => "\xFF\xD8\xFF".b }
- UNREADABLE =
What a host hears about a picture no phone would draw.
'crest: the photo is neither a PNG nor a JPEG, so the card goes out without it'
Instance Method Summary collapse
-
#initialize(photo) ⇒ Photo
constructor
A new instance of Photo.
-
#property ⇒ String
PHOTO property, or nothing where the bytes are in no format a phone reads.
Constructor Details
#initialize(photo) ⇒ Photo
Returns a new instance of Photo.
11 12 13 14 15 |
# File 'lib/crest/photo.rb', line 11 def initialize(photo) @bytes = photo.respond_to?(:binread) ? photo.binread : photo @type = SIGNATURES.find { |_, signature| @bytes.b.start_with? signature }&.first warn UNREADABLE unless @type end |
Instance Method Details
#property ⇒ String
Returns PHOTO property, or nothing where the bytes are in no format a phone reads.
18 19 20 |
# File 'lib/crest/photo.rb', line 18 def property @property ||= "PHOTO;ENCODING=b;TYPE=#{@type}:#{[@bytes].pack 'm0'}" if @type end |