Class: Ariel::Wildcards

Inherits:
Object
  • Object
show all
Defined in:
lib/ariel/wildcards.rb

Overview

Contains all wildcards to be used in rule generation.

Constant Summary collapse

@@list =
{
  :anything=>/.+/,
  :numeric=>/\d+/,
  :alpha_numeric=>/\w+/,
  :alpha=>/[[:alpha:]]+/,
  :capitalized=>/[[:upper:]]+\w+/,
  :all_caps=>/[[:upper:]]+/,
  :html_tag=>/<\/?\w+>|<\w+\s+\/>/,
  :punctuation=>/[[:punct:]]+/
}

Class Method Summary collapse

Class Method Details

.listObject

Returns the hash of wildcard name (symbol) and regular expression pairs.



16
17
18
# File 'lib/ariel/wildcards.rb', line 16

def self.list
  @@list
end

.matching(string) ⇒ Object

Given a string, will return an array of symbols from Wildcards::list that match it.



22
23
24
25
26
27
28
29
30
31
# File 'lib/ariel/wildcards.rb', line 22

def self.matching(string)
  matches=[]
  @@list.each do |name, regex|
    if string[regex]==string
      yield name if block_given?
      matches << name
    end
  end
  matches
end