Class: Mp3file::ID3v2::Tag
- Inherits:
-
Object
- Object
- Mp3file::ID3v2::Tag
- Extended by:
- Forwardable
- Defined in:
- lib/mp3file/id3v2/tag.rb
Constant Summary collapse
- FRAME_HEADER_NAME_REGEX =
/[A-Z][A-Z0-9]{2,3}/
Instance Attribute Summary collapse
-
#frames ⇒ Object
readonly
Returns the value of attribute frames.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#unused_bytes ⇒ Object
readonly
Returns the value of attribute unused_bytes.
Instance Method Summary collapse
- #get_next_frame_header(data, offset) ⇒ Object
-
#initialize(io) ⇒ Tag
constructor
A new instance of Tag.
- #load_frames(io) ⇒ Object
- #size ⇒ Object
Constructor Details
Instance Attribute Details
#frames ⇒ Object (readonly)
Returns the value of attribute frames.
10 11 12 |
# File 'lib/mp3file/id3v2/tag.rb', line 10 def frames @frames end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
10 11 12 |
# File 'lib/mp3file/id3v2/tag.rb', line 10 def header @header end |
#unused_bytes ⇒ Object (readonly)
Returns the value of attribute unused_bytes.
10 11 12 |
# File 'lib/mp3file/id3v2/tag.rb', line 10 def unused_bytes @unused_bytes end |
Instance Method Details
#get_next_frame_header(data, offset) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mp3file/id3v2/tag.rb', line 43 def get_next_frame_header(data, offset) md = data.match(FRAME_HEADER_NAME_REGEX, offset) while md frame_offset = md.begin(0) io = StringIO.new(data[frame_offset, 32]) frame = FrameHeader.new(io, self) if frame.frame_id.to_s =~ FRAME_HEADER_NAME_REGEX return [ frame_offset, frame ] else frame_offset = md.end(0) + 1 md = data.match(FRAME_HEADER_NAME_REGEX, frame_offset) end end [ nil, nil ] end |
#load_frames(io) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mp3file/id3v2/tag.rb', line 21 def load_frames(io) @frames = [] data = io.read(@header.tag_size) data.force_encoding("ASCII-8BIT") offset = 0 loop do frame_offset, frame = get_next_frame_header(data, offset) if frame @frames << frame offset = frame_offset + frame.size else break end end end |
#size ⇒ Object
39 40 41 |
# File 'lib/mp3file/id3v2/tag.rb', line 39 def size @header.tag_size + 10 end |