Class: EXIFR::TIFF::IFD
- Inherits:
-
Object
show all
- Defined in:
- lib/exifr/tiff.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data, offset = nil, type = :image) ⇒ IFD
Returns a new instance of IFD.
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
|
# File 'lib/exifr/tiff.rb', line 487
def initialize(data, offset = nil, type = :image)
@data, @offset, @type, @fields = data, offset, type, {}
pos = offset || @data.readlong(4)
num = @data.readshort(pos)
if pos && num
pos += 2
num.times do
add_field(Field.new(@data, pos))
pos += 12
end
@offset_next = @data.readlong(pos)
end
rescue => ex
EXIFR.logger.warn("Badly formed IFD: #{ex}")
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
507
508
509
510
|
# File 'lib/exifr/tiff.rb', line 507
def method_missing(method, *args)
super unless args.empty? && TAGS.include?(method)
to_hash[method]
end
|
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
485
486
487
|
# File 'lib/exifr/tiff.rb', line 485
def fields
@fields
end
|
#offset ⇒ Object
Returns the value of attribute offset.
485
486
487
|
# File 'lib/exifr/tiff.rb', line 485
def offset
@offset
end
|
#type ⇒ Object
Returns the value of attribute type.
485
486
487
|
# File 'lib/exifr/tiff.rb', line 485
def type
@type
end
|
Instance Method Details
#encode_with(coder) ⇒ Object
539
540
541
|
# File 'lib/exifr/tiff.rb', line 539
def encode_with(coder)
coder["fields"] = @fields
end
|
#height ⇒ Object
513
|
# File 'lib/exifr/tiff.rb', line 513
def height; image_length; end
|
#inspect ⇒ Object
527
528
529
|
# File 'lib/exifr/tiff.rb', line 527
def inspect
to_hash.inspect
end
|
#next ⇒ Object
535
536
537
|
# File 'lib/exifr/tiff.rb', line 535
def next
IFD.new(@data, @offset_next) if next?
end
|
#next? ⇒ Boolean
531
532
533
|
# File 'lib/exifr/tiff.rb', line 531
def next?
@offset_next && @offset_next > 0 && @offset_next < @data.size
end
|
#to_hash ⇒ Object
515
516
517
518
519
520
521
522
523
524
525
|
# File 'lib/exifr/tiff.rb', line 515
def to_hash
@hash ||= @fields.map do |key,value|
if value.nil?
{}
elsif IFD_TAGS.include?(key)
value.to_hash
else
{key => value}
end
end.inject { |m,v| m.merge(v) } || {}
end
|
#to_yaml_properties ⇒ Object
543
544
545
|
# File 'lib/exifr/tiff.rb', line 543
def to_yaml_properties
['@fields']
end
|
#width ⇒ Object
512
|
# File 'lib/exifr/tiff.rb', line 512
def width; image_width; end
|