Class: ParseLine::Line
- Inherits:
-
Object
- Object
- ParseLine::Line
- Defined in:
- lib/metronome-odd/parse_line.rb
Constant Summary collapse
- @@line_regexp_hash =
nil
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(line) ⇒ Line
constructor
A new instance of Line.
- #parse ⇒ Object
- #remove_separators ⇒ Object
Constructor Details
#initialize(line) ⇒ Line
Returns a new instance of Line.
10 11 12 13 14 15 |
# File 'lib/metronome-odd/parse_line.rb', line 10 def initialize(line) if @@line_regexp_hash.nil? @@line_regexp_hash = Hash.new([/^$/,/^$/]) end @line = line end |
Class Method Details
.add_command(symbol, command) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/metronome-odd/parse_line.rb', line 17 def Line.add_command(symbol, command) if @@line_regexp_hash.nil? @@line_regexp_hash = Hash.new([/^$/,[]]) end @@line_regexp_hash[symbol] = command end |
Instance Method Details
#parse ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/metronome-odd/parse_line.rb', line 24 def parse c = nil s = nil self.remove_separators @@line_regexp_hash.each do |symbol, command_regex| if @line.match(command_regex) c = @line.match(command_regex) s = symbol break end end [s, c] end |
#remove_separators ⇒ Object
6 7 8 |
# File 'lib/metronome-odd/parse_line.rb', line 6 def remove_separators @line = @line.gsub(/\s+/, "") end |