Hello all,
Pretty much new to Ruby, and I think I am not grasping something fundamental
here. I've written some classes that grab meta tags from various audio file
formats, and overrode 'to_s" to dump the tags to the console, and "to_a" to
dump the tags to an array for use elsewhere in my program.
I am not sure how to explain my problem, so I will just paste in a session
from irb that shows it:
require 'sneetchalizer' # my class definitions...
x =OggMetaTags.new('/home/music/e/elliottSmith-shootingStar.ogg')
=> #<OggMetaTags:0xa7cc1ac8 [...rest omitted...]
x.to_a
=> ["", "", "", "", "", "", ""]
x.title
=> "Shooting Star"
x.to_a
=> ["Shooting Star", "", "", "", "", "", ""]
x.artist
=> "Elliott Smith"
x.to_a
=> ["Shooting Star", "Elliott Smith", "", "", "", "", ""]
So you can see I need to explicitly call each attribute before my array gets
the value. How can I change this so the array is populated automatically when
called?
Here is the class:
class OggMetaTags < MetaTags
def initialize(filename)
@filename = filename
require 'ogginfo'
@tags = OggInfo.new(@filename)
end
def title
@title = @tags.tag['title']
end
def artist
@artist = @tags.tag['artist']
end
def album
@album = @tags.tag['album']
end
def genre
@genre = @tags.tag['genre']
end
def year
@year = @tags.tag['date']
end
def comment
@comment = super
end
def tracknum
@tracknum = @tags.tag['tracknumber']
end
def to_a
["#@title", "#@artist", "#@album", "#@genre", "#@year", "#@comment",
"#@tracknum"]
end
end
If you need more info or want to see all the code please just ask. Thanks for
consideration,
-d
···
--
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972