Class: RSAC::Lexeme

Inherits:
Object
  • Object
show all
Defined in:
lib/antisamy/csspool/rsac/sac/lexeme.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pattern = nil) {|patterns| ... } ⇒ Lexeme

Returns a new instance of Lexeme.

Yields:

  • (patterns)

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/antisamy/csspool/rsac/sac/lexeme.rb', line 5

def initialize(name, pattern=nil, &block)
  raise ArgumentError, "name required" unless name

  @name = name
  patterns = []

  patterns << pattern if pattern
  yield(patterns) if block_given?

  if patterns.empty?
    raise ArgumentError, "at least one pattern required"
  end

  patterns.collect! do |spattern|
    source = spattern.source
    source = "\\A#{source}"
    Regexp.new(source, Regexp::IGNORECASE + Regexp::MULTILINE, 'n')
  end

  @pattern = Regexp.union(*patterns)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/antisamy/csspool/rsac/sac/lexeme.rb', line 3

def name
  @name
end

#patternObject (readonly)

Returns the value of attribute pattern.



3
4
5
# File 'lib/antisamy/csspool/rsac/sac/lexeme.rb', line 3

def pattern
  @pattern
end