Class: WahWah::Tag
- Inherits:
-
Object
- Object
- WahWah::Tag
- Defined in:
- lib/wahwah/tag.rb
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
-
#album ⇒ Object
readonly
Returns the value of attribute album.
-
#albumartist ⇒ Object
readonly
Returns the value of attribute albumartist.
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#bit_depth ⇒ Object
readonly
Returns the value of attribute bit_depth.
-
#bitrate ⇒ Object
readonly
Returns the value of attribute bitrate.
-
#comments ⇒ Object
readonly
Returns the value of attribute comments.
-
#composer ⇒ Object
readonly
Returns the value of attribute composer.
-
#disc ⇒ Object
readonly
Returns the value of attribute disc.
-
#disc_total ⇒ Object
readonly
Returns the value of attribute disc_total.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#file_size ⇒ Object
readonly
Returns the value of attribute file_size.
-
#genre ⇒ Object
readonly
Returns the value of attribute genre.
-
#lyrics ⇒ Object
readonly
Returns the value of attribute lyrics.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#track ⇒ Object
readonly
Returns the value of attribute track.
-
#track_total ⇒ Object
readonly
Returns the value of attribute track_total.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #images ⇒ Object
-
#initialize(file) ⇒ Tag
constructor
A new instance of Tag.
- #inspect ⇒ Object
Constructor Details
#initialize(file) ⇒ Tag
Returns a new instance of Tag.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/wahwah/tag.rb', line 29 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 |
Instance Attribute Details
#album ⇒ Object (readonly)
Returns the value of attribute album.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def album @album end |
#albumartist ⇒ Object (readonly)
Returns the value of attribute albumartist.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def albumartist @albumartist end |
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def artist @artist end |
#bit_depth ⇒ Object (readonly)
Returns the value of attribute bit_depth.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def bit_depth @bit_depth end |
#bitrate ⇒ Object (readonly)
Returns the value of attribute bitrate.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def bitrate @bitrate end |
#comments ⇒ Object (readonly)
Returns the value of attribute comments.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def comments @comments end |
#composer ⇒ Object (readonly)
Returns the value of attribute composer.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def composer @composer end |
#disc ⇒ Object (readonly)
Returns the value of attribute disc.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def disc @disc end |
#disc_total ⇒ Object (readonly)
Returns the value of attribute disc_total.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def disc_total @disc_total end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def duration @duration end |
#file_size ⇒ Object (readonly)
Returns the value of attribute file_size.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def file_size @file_size end |
#genre ⇒ Object (readonly)
Returns the value of attribute genre.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def genre @genre end |
#lyrics ⇒ Object (readonly)
Returns the value of attribute lyrics.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def lyrics @lyrics end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def sample_rate @sample_rate end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def title @title end |
#track ⇒ Object (readonly)
Returns the value of attribute track.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def track @track end |
#track_total ⇒ Object (readonly)
Returns the value of attribute track_total.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def track_total @track_total end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
8 9 10 |
# File 'lib/wahwah/tag.rb', line 8 def year @year end |
Instance Method Details
#images ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/wahwah/tag.rb', line 58 def images return @images_data if @images_data.empty? @images_data.map do |data| parse_image_data(data) end end |
#inspect ⇒ Object
51 52 53 54 55 56 |
# File 'lib/wahwah/tag.rb', line 51 def inspect inspect_id = ::Kernel.format "%x", (object_id * 2) inspect_attributes_values = INSPECT_ATTRIBUTES.map { |attr_name| "#{attr_name}=#{send(attr_name)}" }.join(" ") "<#{self.class.name}:0x#{inspect_id} #{inspect_attributes_values}>" end |