Class: ID3Tag::Frames::V2::BasicFrame

Inherits:
Object
  • Object
show all
Defined in:
lib/id3tag/frames/v2/basic_frame.rb

Direct Known Subclasses

PictureFrame, TextFrame, UniqueFileIdFrame

Constant Summary collapse

DECOMPRESSED_SIZE_BYTE_COUNT =
4
GROUP_BYTE_COUNT =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, content, flags, major_version_number) ⇒ BasicFrame

Returns a new instance of BasicFrame.



10
11
12
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 10

def initialize(id, content, flags, major_version_number)
  @id, @raw_content, @flags, @major_version_number = id.to_sym, content, flags, major_version_number
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 8

def id
  @id
end

#raw_contentObject (readonly)

Returns the value of attribute raw_content.



8
9
10
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 8

def raw_content
  @raw_content
end

Instance Method Details

#compressed?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 64

def compressed?
  frame_flags.compressed?
end

#contentObject



14
15
16
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 14

def content
  usable_content
end

#data_length_indicator?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 80

def data_length_indicator?
  frame_flags.data_length_indicator?
end

#encrypted?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 68

def encrypted?
  frame_flags.encrypted?
end

#encryption_idObject



31
32
33
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 31

def encryption_id
  read_additional_info_byte(*position_and_count_of_encryption_id_bytes) if encrypted?
end

#final_sizeObject



42
43
44
45
46
47
48
49
50
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 42

def final_size
  pos, count = position_and_count_of_data_length_bytes
  if (compressed? || data_length_indicator?) && pos && count
    raw_content_io.seek(pos)
    SynchsafeInteger.decode(NumberUtil.convert_string_to_32bit_integer(raw_content_io.read(count)))
  else
    raw_content_io.size
  end
end

#group_idObject



27
28
29
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 27

def group_id
  read_additional_info_byte(*position_and_count_of_group_id_bytes) if grouped?
end

#grouped?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 72

def grouped?
  frame_flags.grouped?
end

#inspectObject



84
85
86
87
88
89
90
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 84

def inspect
  if inspectable_content
    "<#{self.class.name} #{id}: #{inspectable_content}>"
  else
    "<#{self.class.name} #{id}>"
  end
end

#inspectable_contentObject



92
93
94
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 92

def inspectable_content
  nil
end

#preserve_on_file_alteration?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 52

def preserve_on_file_alteration?
  frame_flags.preserve_on_file_alteration?
end

#preserve_on_tag_alteration?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 56

def preserve_on_tag_alteration?
  frame_flags.preserve_on_tag_alteration?
end

#read_additional_info_byte(position, byte_count) ⇒ Object



35
36
37
38
39
40
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 35

def read_additional_info_byte(position, byte_count)
  if position && byte_count
    raw_content_io.seek(position)
    raw_content_io.read(byte_count).unpack("C").first
  end
end

#read_only?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 60

def read_only?
  frame_flags.read_only?
end

#unsynchronised?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 76

def unsynchronised?
  frame_flags.unsynchronised?
end

#usable_contentObject



18
19
20
21
22
23
24
25
# File 'lib/id3tag/frames/v2/basic_frame.rb', line 18

def usable_content
  raw_content_io.seek(additional_info_byte_count)
  if unsynchronised?
    StringUtil.undo_unsynchronization(raw_content_io.read)
  else
    raw_content_io.read
  end
end