Class: Metrocot::AnythingPattern
- Inherits:
-
BasePattern
- Object
- BasePattern
- Metrocot::AnythingPattern
- Defined in:
- lib/metrocot.rb
Overview
Matches anything.
Instance Attribute Summary
Attributes inherited from BasePattern
#matched, #metrocot, #name, #node_scraper, #pattern_no, #pred, #source, #succ
Class Method Summary collapse
Instance Method Summary collapse
- #description ⇒ Object
-
#each_match(match_range, match_map) ⇒ Object
always matches the whole thing because it will get matched last…
- #priority ⇒ Object
Methods inherited from BasePattern
#default_scanner, #dump, #dump_match_map, #initialize, #log, #log_match_data, #optional, #with_scanned_match_data
Constructor Details
This class inherits a constructor from Metrocot::BasePattern
Class Method Details
.parse(s) ⇒ Object
522 523 524 525 |
# File 'lib/metrocot.rb', line 522 def self.parse( s ) return nil unless s.index("...") == 0 self.new("...") end |
Instance Method Details
#description ⇒ Object
518 519 520 |
# File 'lib/metrocot.rb', line 518 def description "anything" end |
#each_match(match_range, match_map) ⇒ Object
always matches the whole thing because it will get matched last… it just expands to fill whatever gap
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/metrocot.rb', line 531 def each_match( match_range, match_map ) result = if match_range.start_index > match_range.end_index log( "empty range" ) nil elsif match_range.start_index > match_range.end_index && match_range.start_offset > match_range.end_offset log( "empty node" ) nil elsif match_range.start_index == match_range.end_index || (match_range.start_index + 1 == match_range.end_index && match_range.end_offset == 0) && match_range.hnodes[match_range.start_index].text? log( "single text node range #{match_range.describe}" ) raise "bad range #{match_range.describe}" if match_range.hnodes[match_range.start_index].nil? with_scanned_match_data( match_map, match_range.hnodes[match_range.start_index].inner_text[match_range.start_offset...match_range.end_offset] ) { |match_map| yield( match_range, match_map ) } else log( "multi node range #{match_range.describe}" ) with_scanned_match_data( match_map, match_range.hnodes[match_range.start_index ... match_range.end_index] ) { |match_map| yield( match_range, match_map ) } end end |
#priority ⇒ Object
554 555 556 |
# File 'lib/metrocot.rb', line 554 def priority -7 end |