Class: IPTC::JPEG::Marker
- Inherits:
-
Object
- Object
- IPTC::JPEG::Marker
- Defined in:
- lib/iptc/jpeg/marker.rb
Overview
Marker
A Jpeg marker, generic class used by all others markers
Direct Known Subclasses
IPTC::JPEG::Markers::APP0Marker, IPTC::JPEG::Markers::APP13Marker, IPTC::JPEG::Markers::COMMarker, IPTC::JPEG::Markers::SOIMarker
Constant Summary collapse
- @@missing =
[]
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
-
.NewMarker(type, data, logger) ⇒ Object
The NewMarker constructor method.
Instance Method Summary collapse
-
#initialize(type, data) ⇒ Marker
constructor
A new instance of Marker.
- #l(message) ⇒ Object
-
#parse ⇒ Object
parse the data.
-
#properties ⇒ Object
returns the available properties for the given tag.
- #read(count) ⇒ Object
-
#to_binary(data = nil) ⇒ Object
binary serialization transform the marker to its final form.
- #valid? ⇒ Boolean
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
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
8 9 10 |
# File 'lib/iptc/jpeg/marker.rb', line 8 def prefix @prefix end |
#values ⇒ Object (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 @logger.debug end |
#parse ⇒ Object
parse the data
75 76 77 |
# File 'lib/iptc/jpeg/marker.rb', line 75 def parse return [] end |
#properties ⇒ Object
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
69 70 71 |
# File 'lib/iptc/jpeg/marker.rb', line 69 def valid? return true end |