Class: DataMetaDom::RegExRoster

Inherits:
Object
  • Object
show all
Defined in:
lib/dataMetaDom/util.rb

Overview

Registry for the regexes so we don’t repeat those

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRegExRoster

sets index to 0, initializes hashes



204
205
206
207
208
209
# File 'lib/dataMetaDom/util.rb', line 204

def initialize
    @index = 0
    @i_to_r = {}
    @r_to_i = {}
    @canned = {}
end

Instance Attribute Details

#cannedObject (readonly)

Returns the value of attribute canned.



194
195
196
# File 'lib/dataMetaDom/util.rb', line 194

def canned
  @canned
end

#i_to_rObject (readonly)

Returns the value of attribute i_to_r.



194
195
196
# File 'lib/dataMetaDom/util.rb', line 194

def i_to_r
  @i_to_r
end

#r_to_iObject (readonly)

Returns the value of attribute r_to_i.



194
195
196
# File 'lib/dataMetaDom/util.rb', line 194

def r_to_i
  @r_to_i
end

Class Method Details

.ixToVarName(index) ⇒ Object

Converts the given custom RegEx index to the matching Pattern static final variable name



198
199
200
# File 'lib/dataMetaDom/util.rb', line 198

def ixToVarName(index)
    "REGEX___#{index}___"
end

Instance Method Details

#register(f) ⇒ Object

adds a new regex to the registry



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/dataMetaDom/util.rb', line 212

def register(f)
    var = f.name
    rx = f.regex
    rx = rx[1..-2] if rx.length > 2 && rx.start_with?('/') && rx.end_with?('/')
    k = rx.to_sym
    if CANNED_RX.member?(k)
        if @canned.has_key?(k)
            @canned[k] << var
        else
            @canned[k] = RegExEntry.new(k, var, f.isRequired)
        end
    elsif @r_to_i.has_key?(k)
        # this regex is already registered, just add the variable
        @i_to_r[@index] << var
    else
        @index += 1
        @i_to_r[@index] = RegExEntry.new(k, var, f.isRequired)
        @r_to_i[k] = @index
    end
end