Module: Id3Taginator::Frames::CustomFrames
Instance Method Summary collapse
-
#add_custom_frame(frame_id, content, selector_lambda = nil) ⇒ Object
adds a custom frame Multiple ones can be added, the selector must be given to determine if a frame should be updated or added.
-
#custom_frame(frame_id) ⇒ String?
extracts a custom frame for the given id.
-
#remove_custom_frame(frame_id, selector_lambda = nil) ⇒ Object
removes the frame with the given id or a specific one with the given selector.
Methods included from Frameable
#find_frame, #find_frames, #set_frame_fields, #set_frame_fields_by_selector, #unsupported_frame
Instance Method Details
#add_custom_frame(frame_id, content, selector_lambda = nil) ⇒ Object
adds a custom frame Multiple ones can be added, the selector must be given to determine if a frame should be updated or added
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/id3taginator/frames/custom_frames.rb', line 23 def add_custom_frame(frame_id, content, selector_lambda = nil) if selector_lambda.nil? existing_frame = find_frame(frame_id) else existing_frames = find_frames(frame_id) existing_frame = existing_frames&.find { |f| selector_lambda.call(f) } end unless existing_frame.nil? existing_frame.content = content return end new_frame = CustomFrame.build_frame(content, @options, id3_version: @major_version) new_frame. = @options @frames << new_frame end |
#custom_frame(frame_id) ⇒ String?
extracts a custom frame for the given id
13 14 15 |
# File 'lib/id3taginator/frames/custom_frames.rb', line 13 def custom_frame(frame_id) find_frame(frame_id)&.content end |
#remove_custom_frame(frame_id, selector_lambda = nil) ⇒ Object
removes the frame with the given id or a specific one with the given selector
45 46 47 48 49 50 51 |
# File 'lib/id3taginator/frames/custom_frames.rb', line 45 def remove_custom_frame(frame_id, selector_lambda = nil) if selector_lambda.nil? @frames.delete_if { |f| f.frame_id == frame_id } else @frames.delete_if { |f| f.frame_id == frame_id && selector_lambda.call(f) } end end |