class Etree::InfoFile
This will parse the info file that comes with a show Typical usage might look like:
info_file = Etree::InfoFile.new :directory => "ph1999-12-31.flacf" info_file.parse info_file.band # => "Phish" info_file.date # => "1999-12-31" info_file.venue # => "Big Cypress Seminole Indian Reservation, Big Cypress, FL" info_file.discs.first # => ["Runaway Jim", "Funky Bitch", ...]
Constants
- REGEXPS
- TRACK_REGEXP
Attributes
band[RW]
comments[RW]
date[RW]
directory[RW]
discs[RW]
info_file[RW]
source[RW]
venue[RW]
Public Class Methods
new(attrs={})
click to toggle source
# File lib/etree/info_file.rb, line 36 def initialize(attrs={}) attrs.each do |k,v| send("#{k}=", v) end end
Public Instance Methods
parse(info_file=nil)
click to toggle source
# File lib/etree/info_file.rb, line 42 def parse(info_file=nil) self.info_file = info_file if info_file parse_info end
songs_count()
click to toggle source
# File lib/etree/info_file.rb, line 58 def songs_count Dir["#{directory}/*.flac"].size end
tracks()
click to toggle source
# File lib/etree/info_file.rb, line 62 def tracks @tracks ||= begin tracks = [] discs.each_with_index do |d, dn| d.each_with_index do |t, tn| tracks << Track.new(:name => t, :number => tn + 1, :disc => dn + 1) end end tracks end end
Private Instance Methods
format_track_name(track_name)
click to toggle source
# File lib/etree/info_file.rb, line 133 def format_track_name(track_name) track_name = track_name.to_s segue = track_name =~ />\s*$/ track_name.sub!(/^\d{1,2}:\d{2}\]?\s/,"") # strip timings track_name.sub!(/[*^%>\s]*$/,"") # strip footnote markers track_name << (segue ? ' >' : '') end
info_file_paragraphs()
click to toggle source
# File lib/etree/info_file.rb, line 75 def info_file_paragraphs @info_file_paras ||= File.read(info_file).split(/\s*\r?\n\r?\n/) end
parse_band(paragraph)
click to toggle source
# File lib/etree/info_file.rb, line 96 def parse_band(paragraph) venue = [] paragraph.each_line do |line| line.strip! next if line.empty? if !date self.date = parse_date(line) next if date end if band venue << line else self.band = line end end self.venue = Array(venue).join(", ") end
parse_date(s)
click to toggle source
# File lib/etree/info_file.rb, line 116 def parse_date(s) Chronic.parse(s.to_s.gsub(',','').gsub(/(?:mon|tue|wed|thu|fri|sat|sun)\w*/i,'')) end
parse_info()
click to toggle source
# File lib/etree/info_file.rb, line 79 def parse_info info_file_paragraphs.each do |paragraph| next if $para =~ /\b[\da-f]{32}\b/i if !band or !date or !venue parse_band paragraph elsif source_info_paragraph? paragraph self.source ||= [] self.source << paragraph elsif tracks_paragraph? paragraph parse_tracks paragraph else self.comments ||= [] self.comments << paragraph end end end
parse_tracks(paragraph)
click to toggle source
# File lib/etree/info_file.rb, line 120 def parse_tracks(paragraph) tracks = [] paragraph.each_line do |line| line.strip! if match = line.match(TRACK_REGEXP) tracks << format_track_name(match[2]) end end (self.discs ||= []) << tracks unless tracks.empty? end
source_info_paragraph?(paragraph)
click to toggle source
# File lib/etree/info_file.rb, line 141 def source_info_paragraph?(paragraph) paragraph =~ %r{^(?:source|src|xfer|transfer|seede[rd]|tape[rd]|recorded)\b}mix or paragraph =~ %r{\b(#{REGEXPS[:spots]}|#{REGEXPS[:mics]}|#{REGEXPS[:configs]}|#{REGEXPS[:cables]}|#{REGEXPS[:pres]}|#{REGEXPS[:dats]}|#{REGEXPS[:laptops]}|#{REGEXPS[:digicards]}|#{REGEXPS[:software]})\b} end
tracks_paragraph?(paragraph)
click to toggle source
# File lib/etree/info_file.rb, line 146 def tracks_paragraph?(paragraph) paragraph =~ /\b(cd|set|dis[ck]|volume|set)\b/i or paragraph =~ TRACK_REGEXP or paragraph =~ /^([\*\@\#\$\%\^]+)\s*[-=:]?\s*/ end