class WahWah::Tag

Constants

INSPECT_ATTRIBUTES
INTEGER_ATTRIBUTES

Attributes

album[R]
albumartist[R]
artist[R]
bit_depth[R]
bitrate[R]
comments[R]
composer[R]
disc[R]
disc_total[R]
duration[R]
file_size[R]
genre[R]
sample_rate[R]
title[R]
track[R]
track_total[R]
year[R]

Public Class Methods

new(file) click to toggle source
# File lib/wahwah/tag.rb, line 28
def initialize(file)
  if file.is_a?(IO) || file.is_a?(StringIO)
    @file_size = file.size
    @file_io = file
  else
    @file_size = File.size(file)
    @file_io = File.open(file)
  end

  @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
ensure
  @file_io.close
end

Public Instance Methods

images() click to toggle source
# File lib/wahwah/tag.rb, line 57
def images
  return @images_data if @images_data.empty?

  @images_data.map do |data|
    parse_image_data(data)
  end
end
inspect() click to toggle source
# File lib/wahwah/tag.rb, line 50
def inspect
  inspect_id = ::Kernel.format '%x', (object_id * 2)
  inspect_attributes_values = INSPECT_ATTRIBUTES.map { |attr_name| "#{attr_name}=#{self.send(attr_name)}" }.join(' ')

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

Private Instance Methods

parse() click to toggle source
# File lib/wahwah/tag.rb, line 66
def parse
  raise WahWahNotImplementedError, 'The parse method is not implemented'
end