Class: Marvin::Parsers::RegexpParser
- Inherits:
-
AbstractParser
- Object
- AbstractParser
- Marvin::Parsers::RegexpParser
- Defined in:
- lib/marvin/parsers/regexp_parser.rb
Instance Attribute Summary collapse
-
#current_line ⇒ Object
Returns the value of attribute current_line.
Attributes inherited from AbstractParser
Class Method Summary collapse
-
.register_event(*args) ⇒ Object
Appends an event to the end of the the events callback chain.
Instance Method Summary collapse
-
#initialize(line) ⇒ RegexpParser
constructor
Initialize a new RegexpParser from the given line.
- #to_event ⇒ Object
Methods inherited from AbstractParser
Constructor Details
#initialize(line) ⇒ RegexpParser
Initialize a new RegexpParser from the given line.
29 30 31 |
# File 'lib/marvin/parsers/regexp_parser.rb', line 29 def initialize(line) self.current_line = line end |
Instance Attribute Details
#current_line ⇒ Object
Returns the value of attribute current_line.
11 12 13 |
# File 'lib/marvin/parsers/regexp_parser.rb', line 11 def current_line @current_line end |
Class Method Details
.register_event(*args) ⇒ Object
Appends an event to the end of the the events callback chain. It will be search in order of first-registered when used to match a URL (hence, order matters).
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/marvin/parsers/regexp_parser.rb', line 16 def self.register_event(*args) matcher = args.delete_at(1) # Extract regexp. if args.first.is_a?(Marvin::IRC::Event) event = args.first else event = Marvin::IRC::Event.new(*args) end self.regexp_matchers << matcher self.events << event end |
Instance Method Details
#to_event ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/marvin/parsers/regexp_parser.rb', line 33 def to_event self.regexp_matchers.each_with_index do |matcher, offset| if (match_data = matcher.match(self.current_line)) event = self.events[offset].dup event.raw_arguments = match_data.to_a[1..-1] return event end end # otherwise, return nil return nil end |