Class: BruteMatch

Inherits:
Object
  • Object
show all
Defined in:
lib/soks-view.rb

Constant Summary collapse

IGNORE_CASE =
true

Instance Method Summary collapse

Constructor Details

#initializeBruteMatch

Returns a new instance of BruteMatch.



90
91
92
93
# File 'lib/soks-view.rb', line 90

def initialize
	@matches = Hash.new
	@titles = Array.new #sorted array for speed 
end

Instance Method Details

#[](title) ⇒ Object Also known as: object_for



95
# File 'lib/soks-view.rb', line 95

def []( title ) @matches[ lower_case(title) ] end

#[]=(title, object) ⇒ Object

Use this to add a string to match and an associated object to return if an object is matched.



105
106
107
108
# File 'lib/soks-view.rb', line 105

def []=( title, object )
	@matches[lower_case(title)] = object
	update_titles
end

#delete(title) ⇒ Object



98
99
100
101
# File 'lib/soks-view.rb', line 98

def delete( title ) 
	@matches.delete( title )
	update_titles
end

#match(text, do_not_match = []) ⇒ Object



110
111
112
113
114
115
116
117
# File 'lib/soks-view.rb', line 110

def match( text, do_not_match = [] )
	do_not_match = do_not_match.map { |title| lower_case(title) }
	@titles.each do |title,regexp,page|
		next if do_not_match.include? title
		text.gsub!( regexp ) { |match| "#{$1}#{yield $2, page}#{$3}" }
	end
	text
end