Class: Id3Taginator::Frames::Geo::GeneralEncapsulatedObjectFrame

Inherits:
Id3v2Frame
  • Object
show all
Includes:
HasId
Defined in:
lib/id3taginator/frames/geo/geob_general_encapsulated_object_frame.rb

Constant Summary

Constants inherited from Id3v2Frame

Id3v2Frame::HEADER_SIZE_V_2, Id3v2Frame::HEADER_SIZE_V_3_4

Constants included from Extensions::Encodable

Extensions::Encodable::ISO8859_1, Extensions::Encodable::UNICODE_ZERO, Extensions::Encodable::UTF_16, Extensions::Encodable::UTF_16BE, Extensions::Encodable::UTF_8, Extensions::Encodable::ZERO

Instance Attribute Summary collapse

Attributes inherited from Id3v2Frame

#frame_id, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HasId

#frame_info, included, #supported?

Methods inherited from Id3v2Frame

build_id3_flags, build_v2_frame, build_v3_frame, build_v4_frame, #compression?, #encryption?, #file_alter_preservation?, #frame_size, #group_identity?, #initialize, #re_calc_payload_size, #read_only?, #tag_alter_preservation?, #to_bytes

Methods included from Extensions::ArgumentCheck

#argument_between_num, #argument_boolean, #argument_exactly_chars, #argument_less_than_chars, #argument_more_than_chars, #argument_not_empty, #argument_not_nil, #argument_sym, included

Methods included from Extensions::Encodable

#decode, #decode_using_encoding_byte, #default_encoding_destination_byte, #encode, #encode_and_add_encoding_byte, #encode_string, #find_encoding, #find_encoding_byte, included, #merge, #pad_left, #pad_right, #read_stream_until, #remove_trailing_zeros, #zero_byte

Constructor Details

This class inherits a constructor from Id3Taginator::Frames::Id3v2Frame

Instance Attribute Details

#descriptorObject

Returns the value of attribute descriptor.



11
12
13
# File 'lib/id3taginator/frames/geo/geob_general_encapsulated_object_frame.rb', line 11

def descriptor
  @descriptor
end

#filenameObject

Returns the value of attribute filename.



11
12
13
# File 'lib/id3taginator/frames/geo/geob_general_encapsulated_object_frame.rb', line 11

def filename
  @filename
end

#mime_typeObject

Returns the value of attribute mime_type.



11
12
13
# File 'lib/id3taginator/frames/geo/geob_general_encapsulated_object_frame.rb', line 11

def mime_type
  @mime_type
end

#object_dataObject

Returns the value of attribute object_data.



11
12
13
# File 'lib/id3taginator/frames/geo/geob_general_encapsulated_object_frame.rb', line 11

def object_data
  @object_data
end

Class Method Details

.build_frame(mime_type, filename, descriptor, object_data, options = nil, id3_version: 3) ⇒ Id3v2Frame

builds the general encapsulated object frame

Parameters:

  • mime_type (String)

    the mime type of the object e.g. image/png

  • filename (String)

    the filename

  • descriptor (String)

    the description

  • object_data (String)

    the object data bytes represented as a String (str.bytes)

  • options (Options::Options) (defaults to: nil)

    options to use

  • id3_version (Integer) (defaults to: 3)

    the id3 version to build the frame for

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/id3taginator/frames/geo/geob_general_encapsulated_object_frame.rb', line 23

def self.build_frame(mime_type, filename, descriptor, object_data, options = nil, id3_version: 3)
  supported?('GEOB', id3_version, options)

  mime_type ||= ''
  filename ||= ''
  descriptor ||= ''
  argument_not_nil(object_data, 'object_data')

  frame = new(frame_id(id3_version, options), 0, build_id3_flags(id3_version), '')
  frame.mime_type = mime_type
  frame.filename = filename
  frame.descriptor = descriptor
  frame.object_data = object_data
  frame
end

Instance Method Details

#content_to_bytesObject



51
52
53
54
55
# File 'lib/id3taginator/frames/geo/geob_general_encapsulated_object_frame.rb', line 51

def content_to_bytes
  encoded_filename = encode(@filename, null_terminated: true)
  encoded_descriptor = encode(@descriptor, null_terminated: true)
  merge(default_encoding_destination_byte, @mime_type, ZERO, encoded_filename, encoded_descriptor, @object_data)
end

#process_content(content) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/id3taginator/frames/geo/geob_general_encapsulated_object_frame.rb', line 39

def process_content(content)
  stream = StringIO.new(content)
  encoding = find_encoding(stream.readbyte)

  @mime_type = read_stream_until(stream, ZERO)
  encoded_filename = read_stream_until(stream, zero_byte(encoding))
  @filename = decode(encoded_filename, encoding)
  encoded_descriptor = read_stream_until(stream, zero_byte(encoding))
  @descriptor = decode(encoded_descriptor, encoding)
  @object_data = stream.read
end