class Exif::Tag::Base

The base class that specifies common operations for tag data. All the tag classes are derived from this, and client code shoude use the public methods as interface.

Attributes

IFD[R]
count[R]
data[W]
dataPos[RW]
pos[RW]
tagID[R]

Public Class Methods

new(tagID, ifdname, count) click to toggle source

the argument 'byteorder' is either :intel or :motorola. this is used when packing @data given after initialized.

# File lib/exifparser/tag.rb, line 208
def initialize(tagID, ifdname, count)
  @tagID = tagID
  @IFD = ifdname
  @count = count
  @data = nil
  @formatted = nil
  @pos = nil
  @dataPos = nil
end

Public Instance Methods

formatExposureTime(ss) click to toggle source

format exposure time

# File lib/exifparser/tag.rb, line 276
def formatExposureTime(ss)
  rss = 1.0/ss
  if (rss >= 3.0)
    str = "1/%.0f"%[rss]
  elsif (3.0 > rss && rss > 1.0)
    str = "1/%.1f"%[rss]
  elsif (ss == 1.0)
    str = "1.0"
  elsif (3.0 > ss && ss > 1.0)
    str = "%.1f"%[ss]
  else
    str = "%.0f"%[ss]
  end
  "#{str}sec."
end
formatFNumber(f) click to toggle source

format f number

# File lib/exifparser/tag.rb, line 295
def formatFNumber(f)
  if (f.abs < 10.0)
    str = "%.1f"%[f]
  else
    str = "%.0f"%[f]
  end
  "F#{str}"
end
formatFocalLength(f) click to toggle source

format focal length

# File lib/exifparser/tag.rb, line 264
def formatFocalLength(f)
  if (f.abs < 10.0)
    str = "%.1f"%[f]
  else
    str = "%.0f"%[f]
  end
  "#{str}mm"
end
formatLatLon(f) click to toggle source

format Latitude and Longitude

# File lib/exifparser/tag.rb, line 307
def formatLatLon(f)
  if f[2].to_f == 0.0
    sprintf("%d deg %.2f'",f[0],f[1])
  else
    sprintf("%d deg %d' %.2f\"",f[0],f[1],f[2])
  end
end
inspect() click to toggle source
# File lib/exifparser/tag.rb, line 317
def inspect
  sprintf("#<%s ID=0x%04x, IFD=\"%s\" Name=\"%s\", Format=\"%s\", Count=\"%d\", Value=\"%s\">", self.class, @tagID, @IFD, self.name, self.format, self.count, self.value)
end
name() click to toggle source

return tag's name

# File lib/exifparser/tag.rb, line 257
def name
  self.class.to_s.split("::")[-1]
end
processData() click to toggle source
# File lib/exifparser/tag.rb, line 221
def processData
  @formatted = _formatData(@data)
end
to_s() click to toggle source

String representation of tag's value this is the default method that simply sends Object#to_s to @formatted. Subclasses may override this so that it returns more human-readable form.

# File lib/exifparser/tag.rb, line 239
def to_s
  if self.is_a? Formatter::Undefined
    length = @formatted.length
    data = length > 8 ? @formatted[0, 8] : @formatted
    ret = ""
    data.each do |dat|
      ret += sprintf("%02X ", dat)
    end
    ret += %Q[...(#{length} bytes)] if length > data.length
    return ret
  else
    @formatted.to_s
  end
end
value() click to toggle source

return tag's value: simply returns @formatted as it is.

# File lib/exifparser/tag.rb, line 228
def value
  @formatted
end

Private Instance Methods

partition_data(count) { |data| ... } click to toggle source
# File lib/exifparser/tag.rb, line 325
def partition_data(count)
  i = 0
  bytes = @data.size / count
  while @data[i]
    yield @data[i..i+bytes-1]
    i = i + bytes
  end
end