Class: MidiLyrics::Parser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ Parser

Returns a new instance of Parser.



78
79
80
81
82
83
84
85
86
# File 'lib/midi_lyrics.rb', line 78

def initialize(file, options = {})
  options = { repeating: false }.merge(options)
  @file = file
  @repeating = options[:repeating]

  unless File.exists?(file)
    raise MidiLyrics::FileNotFound
  end
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



76
77
78
# File 'lib/midi_lyrics.rb', line 76

def file
  @file
end

#repeatingObject (readonly)

Returns the value of attribute repeating.



76
77
78
# File 'lib/midi_lyrics.rb', line 76

def repeating
  @repeating
end

Instance Method Details

#extractObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/midi_lyrics.rb', line 88

def extract
  read_sequence_from_file
  load_tempo_track
  load_tracks
  calculate_durations
  load_lyrics
  remove_heading_blank_lines
  consolidate_empty_syllables
  remove_lines_trailing_spaces
  fix_durations
  remove_repeating unless repeating
  calculate_seconds
  @lyrics.collect(&:as_json)
end