Class: IPTC::JPEG::Marker

Inherits:
Object
  • Object
show all
Defined in:
lib/iptc/jpeg/marker.rb

Overview

Marker

A Jpeg marker, generic class used by all others markers

Constant Summary collapse

@@missing =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, data) ⇒ Marker

Returns a new instance of Marker.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/iptc/jpeg/marker.rb', line 42

def initialize(type, data)
    @logger = Logger.new(STDOUT)
    @logger.datetime_format = "%H:%M:%S"
    @logger.level = $DEBUG?(Logger::DEBUG):(Logger::INFO)
    
    @original_content = data
  
    @content = StringIO.new(data)
    @type = @content.read(2)
    @size = @content.read(2).unpack('n')[0]-2
  
    if !valid?
        raise InvalidBlockException.new("In block #{self.class}: invalid marker\n#{@content.read(20)}")
    end

    @prefix = self.class.to_s
  
    @prefix = @prefix[@prefix.rindex("::")+2..-7]
    if @prefix==""
        @prefix= 'Marker'
    end

    @values = Hash.new
end

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



8
9
10
# File 'lib/iptc/jpeg/marker.rb', line 8

def prefix
  @prefix
end

#valuesObject (readonly)

Returns the value of attribute values.



9
10
11
# File 'lib/iptc/jpeg/marker.rb', line 9

def values
  @values
end

Class Method Details

.NewMarker(type, data, logger) ⇒ Object

The NewMarker constructor method. Inspect the object space in order to find something usable later



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/iptc/jpeg/marker.rb', line 15

def Marker.NewMarker(type, data, logger)
  marker_class = "#{type}Marker"
    if JPEG::Markers.constants.include?(marker_class.to_sym)
        return JPEG::Markers.const_get(marker_class).new(type, data)
    else
      if !@@missing.include?(type)
        logger.debug "Marker #{type+"Marker"} not found." if logger!=nil
        @@missing << type
      end
    end
    return Marker.new(type,data)
end

Instance Method Details

#l(message) ⇒ Object



28
29
30
# File 'lib/iptc/jpeg/marker.rb', line 28

def l message
  @logger.debug message
end

#parseObject

parse the data



75
76
77
# File 'lib/iptc/jpeg/marker.rb', line 75

def parse
    return []
end

#propertiesObject

returns the available properties for the given tag



80
81
82
# File 'lib/iptc/jpeg/marker.rb', line 80

def properties
    return []
end

#read(count) ⇒ Object



66
67
68
# File 'lib/iptc/jpeg/marker.rb', line 66

def read count
    return @content.read(count)
end

#to_binary(data = nil) ⇒ Object

binary serialization transform the marker to its final form



34
35
36
37
38
39
40
# File 'lib/iptc/jpeg/marker.rb', line 34

def to_binary data=nil
    if data!=nil
        return @type+[data.length+2].pack('n')+data
    else
        return @original_content
    end
end

#valid?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/iptc/jpeg/marker.rb', line 69

def valid?
    return true
end