Class: Cul::Image::Properties::Exif::IFD_Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/cul_image_props/image/properties/exif/types.rb

Overview

for ease of dealing with tags

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_id, field_type, tag_entry, values, field_offset, count) ⇒ IFD_Tag

Returns a new instance of IFD_Tag.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 96

def initialize( tag_id, field_type, tag_entry, values, field_offset, count)
    # tag ID number
    @tag = tag_id
    # field type as index into FIELD_TYPES
    @field_type = field_type
    # the TagEntry looked up for this tag_id
    @tag_entry = tag_entry
    # offset of start of field in bytes from beginning of IFD
    @field_offset = field_offset
    # length of data field in bytes
    @count = count
    typelen = FIELD_TYPES[@field_type].length
    @field_length = count * typelen
    # either a string or array of data items
    @values = values
end

Instance Attribute Details

#field_lengthObject

Returns the value of attribute field_length.



95
96
97
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 95

def field_length
  @field_length
end

#field_offsetObject

Returns the value of attribute field_offset.



95
96
97
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 95

def field_offset
  @field_offset
end

#field_typeObject

Returns the value of attribute field_type.



95
96
97
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 95

def field_type
  @field_type
end

#tagObject

Returns the value of attribute tag.



95
96
97
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 95

def tag
  @tag
end

#valuesObject

Returns the value of attribute values.



95
96
97
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 95

def values
  @values
end

Instance Method Details

#inspectObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 131

def inspect
    begin
        s= format("(0x%04X) %s=%s @ %d", @tag,
                                    FIELD_TYPES[@field_type].name,
                                    printable,
                                    @field_offset)
    rescue
        s= format("(%s) %s=%s @ %s", @tag.to_s,
                                    FIELD_TYPES[@field_type].name,
                                    printable,
                                    @field_offset.to_s)
    end
    return s
end

#printableObject



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 113

def printable
  @printable ||= begin
    if @tag_entry.translates?
      @tag_entry.translate @values
    elsif @count == 1 and @field_type != 2
        @values[0].to_s
    elsif @count > 50 and @values.length > 20
        (field_type == 2) ? (@values[0...20] + '...') : ("[" + @values[0...20].join(',') + ", ... ]")
    else
        @values.inspect
    end
  end
end

#to_sObject



127
128
129
# File 'lib/cul_image_props/image/properties/exif/types.rb', line 127

def to_s
    printable
end