Class: WahWah::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/wahwah/tag.rb

Direct Known Subclasses

AsfTag, FlacTag, ID3::V1, ID3::V2, Mp3Tag, Mp4Tag, OggTag, RiffTag

Constant Summary collapse

INTEGER_ATTRIBUTES =
i[disc disc_total track track_total]
INSPECT_ATTRIBUTES =
i[
  title
  artist
  album
  albumartist
  composer
  comments
  track
  track_total
  genre
  year
  disc
  disc_total
  lyrics
  duration
  bitrate
  sample_rate
  bit_depth
  file_size
]

Instance Method Summary collapse

Constructor Details

#initialize(io, from_path: false) ⇒ Tag

Returns a new instance of Tag.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wahwah/tag.rb', line 29

def initialize(io, from_path: false)
  @from_path = from_path
  @file_size = io.size
  @file_io = io

  @comments = []
  @images_data = []

  parse if @file_size > 0

  INTEGER_ATTRIBUTES.each do |attr_name|
    value = instance_variable_get("@#{attr_name}")&.to_i
    instance_variable_set("@#{attr_name}", value)
  end
end

Instance Method Details

#imagesObject



52
53
54
55
56
57
58
# File 'lib/wahwah/tag.rb', line 52

def images
  return @images_data if @images_data.empty?

  @images ||= @images_data.map do |data|
    parse_image_data(data)
  end
end

#inspectObject



45
46
47
48
49
50
# File 'lib/wahwah/tag.rb', line 45

def inspect
  inspect_id = ::Kernel.format "%x", (object_id * 2)
  inspect_attributes_values = INSPECT_ATTRIBUTES.map { |attr_name| "#{attr_name}: #{send(attr_name).inspect}" }.join(", ")

  "<#{self.class.name}:0x#{inspect_id} #{inspect_attributes_values}>"
end