Class: RubyCue::Cuesheet

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycue/cuesheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cuesheet, track_duration = nil) ⇒ Cuesheet

Returns a new instance of Cuesheet.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rubycue/cuesheet.rb', line 5

def initialize(cuesheet, track_duration=nil)
  @cuesheet = cuesheet      
  @reg = {
    :track => %r(TRACK (\d{1,3}) AUDIO),
    :performer => %r(PERFORMER "(.*)"),
    :title => %r(TITLE "(.*)"),
    :index => %r(INDEX \d{1,3} (\d{1,3}):(\d{1,2}):(\d{1,2})),
    :file => %r(FILE "(.*)"),
    :genre => %r(REM GENRE (.*)\b)
  }
  @track_duration = RubyCue::Index.new(track_duration) if track_duration
end

Instance Attribute Details

#cuesheetObject (readonly)

Returns the value of attribute cuesheet.



3
4
5
# File 'lib/rubycue/cuesheet.rb', line 3

def cuesheet
  @cuesheet
end

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/rubycue/cuesheet.rb', line 3

def file
  @file
end

#genreObject (readonly)

Returns the value of attribute genre.



3
4
5
# File 'lib/rubycue/cuesheet.rb', line 3

def genre
  @genre
end

#performerObject (readonly)

Returns the value of attribute performer.



3
4
5
# File 'lib/rubycue/cuesheet.rb', line 3

def performer
  @performer
end

#songsObject (readonly)

Returns the value of attribute songs.



3
4
5
# File 'lib/rubycue/cuesheet.rb', line 3

def songs
  @songs
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/rubycue/cuesheet.rb', line 3

def title
  @title
end

#track_durationObject (readonly)

Returns the value of attribute track_duration.



3
4
5
# File 'lib/rubycue/cuesheet.rb', line 3

def track_duration
  @track_duration
end

Instance Method Details

#parse!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubycue/cuesheet.rb', line 18

def parse!
  @songs = parse_titles.map{|title| {:title => title}}
  @songs.each_with_index do |song, i|
    song[:performer] = parse_performers[i]
    song[:track] = parse_tracks[i]
    song[:index] = parse_indices[i]
    song[:file] = parse_files[i]
  end
  parse_genre
  raise RubyCue::InvalidCuesheet.new("Field amounts are not all present. Cuesheet is malformed!") unless valid?
  calculate_song_durations!
  true
end

#position(value) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/rubycue/cuesheet.rb', line 32

def position(value)
  index = Index.new(value)
  return @songs.first if index < @songs.first[:index]
  @songs.each_with_index do |song, i|
    return song if song == @songs.last
    return song if between(song[:index], @songs[i+1][:index], index)
  end
end

#valid?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
# File 'lib/rubycue/cuesheet.rb', line 41

def valid?
  @songs.all? do |song|
    [:performer, :track, :index, :title].all? do |key|
      song[key] != nil
    end
  end
end