Class: Id3Taginator::Frames::Text::GenreFrame
- Inherits:
-
Id3v2Frame
- Object
- Id3v2Frame
- Id3Taginator::Frames::Text::GenreFrame
- Includes:
- HasId
- Defined in:
- lib/id3taginator/frames/text/tcon_genre_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
-
#genres ⇒ Object
Returns the value of attribute genres.
Attributes inherited from Id3v2Frame
Class Method Summary collapse
-
.build_frame(genres, options = nil, id3_version: 3) ⇒ Id3v2Frame
builds the genre 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
#genres ⇒ Object
Returns the value of attribute genres.
11 12 13 |
# File 'lib/id3taginator/frames/text/tcon_genre_frame.rb', line 11 def genres @genres end |
Class Method Details
.build_frame(genres, options = nil, id3_version: 3) ⇒ Id3v2Frame
builds the genre frame
20 21 22 23 24 25 26 27 28 |
# File 'lib/id3taginator/frames/text/tcon_genre_frame.rb', line 20 def self.build_frame(genres, = nil, id3_version: 3) supported?('TCON', id3_version, ) argument_not_empty(genres, 'genres') frame = new(frame_id(id3_version, ), 0, build_id3_flags(id3_version), '') frame.genres = genres.is_a?(Array) ? genres : [genres] frame end |
Instance Method Details
#content_to_bytes ⇒ Object
44 45 46 47 48 |
# File 'lib/id3taginator/frames/text/tcon_genre_frame.rb', line 44 def content_to_bytes raise Errors::Id3TagError, 'Genres can\'t be empty' if @genres.nil? || @genres.empty? encode_and_add_encoding_byte(genres_to_string(@genres)) end |
#genres_to_string(genres) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/id3taginator/frames/text/tcon_genre_frame.rb', line 50 def genres_to_string(genres) result = '' genres.each do |genre| g = Genres.genre_by_name(genre) g = g.is_a?(Integer) ? "(#{g})" : "((#{g})" g = '(RX)' if g == '((Remix)' g = '(CR)' if g == '((Cover)' result += g end result end |
#process_content(content) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/id3taginator/frames/text/tcon_genre_frame.rb', line 30 def process_content(content) genre_str = decode_using_encoding_byte(content) genre_ids = parse_genres(genre_str) @genres = [] genre_ids.each do |g| next @genres << Genres.genre(g.to_i) if g.match(/^(\d)+$/) next @genres << 'Remix' if g == 'RX' next @genres << 'Cover' if g == 'CR' @genres << g end end |