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 track track_total genre year disc disc_total duration bitrate sample_rate bit_depth)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Tag

Returns a new instance of Tag.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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
end

Instance Attribute Details

#albumObject (readonly)

Returns the value of attribute album.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def album
  @album
end

#albumartistObject (readonly)

Returns the value of attribute albumartist.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def albumartist
  @albumartist
end

#artistObject (readonly)

Returns the value of attribute artist.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def artist
  @artist
end

#bit_depthObject (readonly)

Returns the value of attribute bit_depth.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def bit_depth
  @bit_depth
end

#bitrateObject (readonly)

Returns the value of attribute bitrate.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def bitrate
  @bitrate
end

#commentsObject (readonly)

Returns the value of attribute comments.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def comments
  @comments
end

#composerObject (readonly)

Returns the value of attribute composer.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def composer
  @composer
end

#discObject (readonly)

Returns the value of attribute disc.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def disc
  @disc
end

#disc_totalObject (readonly)

Returns the value of attribute disc_total.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def disc_total
  @disc_total
end

#durationObject (readonly)

Returns the value of attribute duration.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def duration
  @duration
end

#file_sizeObject (readonly)

Returns the value of attribute file_size.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def file_size
  @file_size
end

#genreObject (readonly)

Returns the value of attribute genre.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def genre
  @genre
end

#sample_rateObject (readonly)

Returns the value of attribute sample_rate.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def sample_rate
  @sample_rate
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def title
  @title
end

#trackObject (readonly)

Returns the value of attribute track.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def track
  @track
end

#track_totalObject (readonly)

Returns the value of attribute track_total.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def track_total
  @track_total
end

#yearObject (readonly)

Returns the value of attribute year.



8
9
10
# File 'lib/wahwah/tag.rb', line 8

def year
  @year
end

Instance Method Details

#imagesObject



55
56
57
58
59
60
61
# File 'lib/wahwah/tag.rb', line 55

def images
  return @images_data if @images_data.empty?

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

#inspectObject



48
49
50
51
52
53
# File 'lib/wahwah/tag.rb', line 48

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