lib/regexp-examples/groups.rb in regexp-examples-0.5.0 vs lib/regexp-examples/groups.rb in regexp-examples-0.5.1
- old
+ new
@@ -21,40 +21,40 @@
# Override to preserve subgroups
GroupResult.new(super.to_s, group_id, subgroups)
end
end
- module GroupWithOptions
- attr_reader :options
+ module GroupWithIgnoreCase
+ attr_reader :ignorecase
def result
group_result = super
- if options[:ignorecase]
+ if ignorecase
group_result
.concat( group_result.map(&:swapcase) )
.uniq
else
group_result
end
end
end
class SingleCharGroup
- prepend GroupWithOptions
- def initialize(char, options)
+ prepend GroupWithIgnoreCase
+ def initialize(char, ignorecase)
@char = char
- @options = options
+ @ignorecase = ignorecase
end
def result
[GroupResult.new(@char)]
end
end
class CharGroup
- prepend GroupWithOptions
- def initialize(chars, options)
+ prepend GroupWithIgnoreCase
+ def initialize(chars, ignorecase)
@chars = chars
- @options = options
+ @ignorecase = ignorecase
if chars[0] == "^"
@negative = true
@chars = @chars[1..-1]
else
@negative = false
@@ -117,28 +117,30 @@
chars
end
end
class DotGroup
- prepend GroupWithOptions
- def initialize(options={})
- @options = options
+ attr_reader :multiline
+ def initialize(multiline)
+ @multiline = multiline
end
def result
- CharSets::Any.map do |result|
+ chars = CharSets::Any
+ chars |= ["\n"] if multiline
+ chars.map do |result|
GroupResult.new(result)
end
end
end
class MultiGroup
- prepend GroupWithOptions
+ prepend GroupWithIgnoreCase
attr_reader :group_id
- def initialize(groups, group_id, options)
+ def initialize(groups, group_id, ignorecase)
@groups = groups
@group_id = group_id
- @options = options
+ @ignorecase = ignorecase
end
# Generates the result of each contained group
# and adds the filled group of each result to
# itself