Class: Id3Taginator::Frames::Picture::PictureFrame
- Inherits:
-
Id3v2Frame
- Object
- Id3v2Frame
- Id3Taginator::Frames::Picture::PictureFrame
- Includes:
- HasId
- Defined in:
- lib/id3taginator/frames/picture/apic_picture_frame.rb
Constant Summary collapse
- LINK_MIME =
'-->'
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
-
#descriptor ⇒ Object
Returns the value of attribute descriptor.
-
#mime_type ⇒ Object
Returns the value of attribute mime_type.
-
#picture_data ⇒ Object
Returns the value of attribute picture_data.
-
#picture_type ⇒ Object
Returns the value of attribute picture_type.
Attributes inherited from Id3v2Frame
Class Method Summary collapse
-
.build_frame(mime_type, picture_type, descriptor, picture_data, options = nil, id3_version: 3) ⇒ Id3v2Frame
builds the picture frame.
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
#descriptor ⇒ Object
Returns the value of attribute descriptor.
13 14 15 |
# File 'lib/id3taginator/frames/picture/apic_picture_frame.rb', line 13 def descriptor @descriptor end |
#mime_type ⇒ Object
Returns the value of attribute mime_type.
13 14 15 |
# File 'lib/id3taginator/frames/picture/apic_picture_frame.rb', line 13 def mime_type @mime_type end |
#picture_data ⇒ Object
Returns the value of attribute picture_data.
13 14 15 |
# File 'lib/id3taginator/frames/picture/apic_picture_frame.rb', line 13 def picture_data @picture_data end |
#picture_type ⇒ Object
Returns the value of attribute picture_type.
13 14 15 |
# File 'lib/id3taginator/frames/picture/apic_picture_frame.rb', line 13 def picture_type @picture_type end |
Class Method Details
.build_frame(mime_type, picture_type, descriptor, picture_data, options = nil, id3_version: 3) ⇒ Id3v2Frame
builds the picture frame
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/id3taginator/frames/picture/apic_picture_frame.rb', line 25 def self.build_frame(mime_type, picture_type, descriptor, picture_data, = nil, id3_version: 3) supported?('APIC', id3_version, ) argument_not_nil(mime_type, 'mime_type') descriptor ||= '' argument_less_than_chars(descriptor, 'descriptor', 64) argument_not_nil(picture_data, 'picture_data') picture_type ||= :OTHER argument_sym(picture_type, 'picture_type') mime_type = "image/#{mime_type}" if !mime_type.include?('/') && mime_type != LINK_MIME frame = new(frame_id(id3_version, ), 0, build_id3_flags(id3_version), '') frame.mime_type = mime_type frame.picture_type = picture_type frame.descriptor = descriptor frame.picture_data = picture_data frame end |
Instance Method Details
#content_to_bytes ⇒ Object
57 58 59 60 61 |
# File 'lib/id3taginator/frames/picture/apic_picture_frame.rb', line 57 def content_to_bytes pic_type = [PictureType.type(@picture_type)].pack('C*') encoded_descriptor = encode(@descriptor, null_terminated: true) merge(default_encoding_destination_byte, @mime_type, ZERO, pic_type, encoded_descriptor, @picture_data) end |
#process_content(content) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/id3taginator/frames/picture/apic_picture_frame.rb', line 47 def process_content(content) stream = StringIO.new(content) encoding = find_encoding(stream.readbyte) @mime_type = read_stream_until(stream, ZERO) @picture_type = PictureType.type_by_value(stream.readbyte) encoded_descriptor = read_stream_until(stream, zero_byte(encoding)) @descriptor = decode(encoded_descriptor, encoding) @picture_data = stream.read end |