Module: RandallRegExp::CharSets

Included in:
CharClass
Defined in:
lib/randall/charclass.rb

Overview

:nodoc: all

Instance Method Summary collapse

Instance Method Details

#all_charsObject Also known as: ascii



16
17
18
# File 'lib/randall/charclass.rb', line 16

def all_chars
  @@ascii ||= strseq(0, 0x7f)
end

#controlObject



25
26
27
# File 'lib/randall/charclass.rb', line 25

def control
  @@control ||= strseq(0, 0x1f) << 0x7f
end

#decimal_numberObject Also known as: digit



29
30
31
# File 'lib/randall/charclass.rb', line 29

def decimal_number
  @@decimal_number ||= (0..9).to_a.map(&:to_s)
end

#graphObject



21
22
23
# File 'lib/randall/charclass.rb', line 21

def graph
  @@graph ||= strseq(0x21, 0x7e)
end

#letterObject



44
45
46
# File 'lib/randall/charclass.rb', line 44

def letter
  @@letter ||= self.lower_letter + self.upper_letter
end

#lower_letterObject



34
35
36
37
38
# File 'lib/randall/charclass.rb', line 34

def lower_letter
  @@lower_letter ||= 26.times.map do |i|
    ('a'.ord + i).chr
  end
end

#punctuationObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/randall/charclass.rb', line 52

def punctuation
  # CHECK: which chars belong to this set?
  @@punct ||= ['!', "\"", '#', #'$', 
               '%', '&', "'", '(', ')',
               '*', #'+', 
               '-', '.', '/', ':', ';', '<', #'=', '>',
               '?', '@', '[', '\\', ']', #'^', 
               '_', #'`',
               '{', #'|', 
               '}', #'~'
               ]
end

#spaceObject



48
49
50
# File 'lib/randall/charclass.rb', line 48

def space
  @@space ||= ["\s", "\t", "\r", "\n", "\v", "\f"]
end

#strseq(from, to) ⇒ Object



12
13
14
# File 'lib/randall/charclass.rb', line 12

def strseq(from, to)
  (from..to).map(&:chr)
end

#upper_letterObject



40
41
42
# File 'lib/randall/charclass.rb', line 40

def upper_letter
  @@upper_letter ||= self.lower_letter.map(&:upcase)
end

#wordObject



74
75
76
# File 'lib/randall/charclass.rb', line 74

def word
  @@word ||= self.letter + self.digit << '_'
end

#xcharObject



65
66
67
68
# File 'lib/randall/charclass.rb', line 65

def xchar
  c = ['a', 'b', 'c', 'd', 'e']
  c += c.map(&:upcase)
end

#xdigitObject



70
71
72
# File 'lib/randall/charclass.rb', line 70

def xdigit
  @@xdigit ||= self.digit + self.xchar
end