Class: ID3Tag::Frames::V2::FrameFlags

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

Constant Summary collapse

FLAG_MAP_IN_APPEARANCE_ORDER_BY_VERSION =
{
  3 => {
    :status_flags => [ :preserve_on_tag_alteration, :preserve_on_file_alteration, :read_only, nil, nil, nil, nil, nil ],
    :format_flags => [ :compressed, :encrypted, :grouped, nil, nil, nil, nil, nil ]
  },
  4 => {
    :status_flags => [ nil, :preserve_on_tag_alteration, :preserve_on_file_alteration, :read_only, nil, nil, nil, nil ],
    :format_flags => [ nil, :grouped, nil, nil, :compressed, :encrypted, :unsynchronised, :data_length_indicator ]
  }
}
ADDITIONAL_INFO_BYTES_IN_APPEARANCE_ORDER_BY_VERSION =
{
  3 => [
    [:compressed?, 4], [:encrypted?, 1], [:grouped?, 1]
  ],
  4 => [
    [:grouped?, 1], [:encrypted?, 1], [:data_length_indicator?, 4]
  ]
}

Instance Method Summary collapse

Constructor Details

#initialize(flag_bytes, major_version_number) ⇒ FrameFlags

Returns a new instance of FrameFlags.



25
26
27
28
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 25

def initialize(flag_bytes, major_version_number)
  @flag_bytes = flag_bytes
  @major_version_number = major_version_number
end

Instance Method Details

#additional_info_byte_countObject



62
63
64
65
66
67
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 62

def additional_info_byte_count
  additional_info_flags_in_effect.inject(0) do |total, query|
    total += query.last
    total
  end
end

#additional_info_flags_in_effectObject



100
101
102
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 100

def additional_info_flags_in_effect
  current_additional_info_map.reject { |q| !self.send(q.first) }
end

#compressed?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 42

def compressed?
  flag(:format_flags, :compressed) == 1
end

#data_length_indicator?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 58

def data_length_indicator?
  flag(:format_flags, :data_length_indicator) == 1
end

#encrypted?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 46

def encrypted?
  flag(:format_flags, :encrypted) == 1
end

#find_position_and_length_for_additional_info(*methods_of_interest) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 87

def find_position_and_length_for_additional_info(*methods_of_interest)
  start_position = 0
  target_info_byte_count = nil
  additional_info_flags_in_effect.map do |query_method, byte_count|
    start_position += (byte_count) unless methods_of_interest.include?(query_method)
    if methods_of_interest.include?(query_method)
      target_info_byte_count = byte_count
      break
    end
  end
  [start_position, target_info_byte_count]
end

#grouped?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 50

def grouped?
  flag(:format_flags, :grouped) == 1
end

#position_and_count_of_data_length_bytesObject



69
70
71
72
73
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 69

def position_and_count_of_data_length_bytes
  if data_length_indicator? || compressed?
    find_position_and_length_for_additional_info(:data_length_indicator?, :compressed?)
  end
end

#position_and_count_of_encryption_id_bytesObject



81
82
83
84
85
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 81

def position_and_count_of_encryption_id_bytes
  if encrypted?
    find_position_and_length_for_additional_info(:encrypted?)
  end
end

#position_and_count_of_group_id_bytesObject



75
76
77
78
79
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 75

def position_and_count_of_group_id_bytes
  if grouped?
    find_position_and_length_for_additional_info(:grouped?)
  end
end

#preserve_on_file_alteration?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 34

def preserve_on_file_alteration?
  flag(:status_flags, :preserve_on_file_alteration) != 1
end

#preserve_on_tag_alteration?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 30

def preserve_on_tag_alteration?
  flag(:status_flags, :preserve_on_tag_alteration) != 1
end

#read_only?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 38

def read_only?
  flag(:status_flags, :read_only) == 1
end

#unsynchronised?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/id3tag/frames/v2/frame_flags.rb', line 54

def unsynchronised?
  flag(:format_flags, :unsynchronised) == 1
end