class RegExpert
Attributes
steps[RW]
Public Class Methods
new()
click to toggle source
# File lib/reg_expert.rb, line 4 def initialize @steps = [] end
Public Instance Methods
at_least(count)
click to toggle source
# File lib/reg_expert.rb, line 38 def at_least(count) @steps << Proc.new do |step| Step.new("#{step.regexp_string}{#{count},}") end self end
character()
click to toggle source
# File lib/reg_expert.rb, line 55 def character steps << CharacterStep.new self end
Also aliased as: characters
digit(digit = nil)
click to toggle source
# File lib/reg_expert.rb, line 18 def digit(digit = nil) steps << DigitStep.new(digit) self end
Also aliased as: digits
exactly(count)
click to toggle source
# File lib/reg_expert.rb, line 26 def exactly(count) @steps << Proc.new do |step| Step.new("#{step.regexp_string}{#{count}}") end self end
find(arg)
click to toggle source
# File lib/reg_expert.rb, line 12 def find(arg) steps << CharacterStep.new(arg) self end
match(test_string)
click to toggle source
# File lib/reg_expert.rb, line 8 def match(test_string) regex_for_steps.match(test_string) end
one()
click to toggle source
# File lib/reg_expert.rb, line 34 def one exactly(1) end
space()
click to toggle source
# File lib/reg_expert.rb, line 61 def space @steps << Step.new("\\s") self end
to_regex()
click to toggle source
# File lib/reg_expert.rb, line 69 def to_regex regex_for_steps end
word()
click to toggle source
# File lib/reg_expert.rb, line 46 def word @steps << Step.new("\\b") self end
Also aliased as: end_of_word, beginning_of_word
Private Instance Methods
parsed_steps()
click to toggle source
# File lib/reg_expert.rb, line 75 def parsed_steps @steps = @steps.map.with_index do |step, index| if step.is_a?(Proc) parsed_val = step.call(steps[index + 1]) steps.delete_at(index + 1) parsed_val else step end end end
regex_for_steps()
click to toggle source
# File lib/reg_expert.rb, line 89 def regex_for_steps Regexp.new parsed_steps.collect(&:regexp_string).join end