Module: Id3Taginator::Frames::PictureFrames

Includes:
Frameable
Included in:
Id3v2Tag
Defined in:
lib/id3taginator/frames/picture_frames.rb

Instance Method Summary collapse

Methods included from Frameable

#find_frame, #find_frames, #set_frame_fields, #set_frame_fields_by_selector, #unsupported_frame

Instance Method Details

#picturesArray<Frames::Picture::Entities::Picture>

extracts the pictures (APIC/PIC)

Returns:



11
12
13
14
15
16
# File 'lib/id3taginator/frames/picture_frames.rb', line 11

def pictures
  frame = find_frames(Picture::PictureFrame.frame_id(@major_version, @options))
  return [] if frame.nil? || frame.empty?

  frame.map { |f| Picture::Entities::Picture.new(f.mime_type, f.picture_type, f.descriptor, f.picture_data) }
end

#pictures=(picture) ⇒ Object Also known as: add_picture

adds a pictures (APIC/PIC) Multiple ones can be added, as long as they have a different picture_type

Parameters:



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

def pictures=(picture)
  if picture.picture_type == Frames::Picture::PictureType::PIXELS_32X32_FILE_ICON__PNG_ONLY ||
     picture.picture_type == Frames::Picture::PictureType::OTHER_FILE_ICON
    frames = pictures
    if frames.any? { |f| f.picture_type == picture.picture_type }
      raise Errors::Id3TagError, "Only one frame of type #{picture.picture_type} is allowed"
    end
  end

  set_frame_fields_by_selector(Picture::PictureFrame, %i[@mime_type @picture_type @descriptor @picture_data],
                               lambda { |f|
                                 f.picture_type == picture.picture_type &&
                                   f.descriptor == picture.descriptor
                               },
                               picture.mime_type, picture.picture_type, picture.descriptor, picture.picture_data)
end

#remove_picture(descriptor) ⇒ Object

removes a pictures for the specific descriptor

Parameters:

  • descriptor (String)

    the descriptor



44
45
46
47
48
# File 'lib/id3taginator/frames/picture_frames.rb', line 44

def remove_picture(descriptor)
  @frames.delete_if do |f|
    f.frame_id == Picture::PictureFrame.frame_id(@major_version, @options) && f.descriptor == descriptor
  end
end