Class: Meteor::Core::Util::PatternCache

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

Overview

パターンキャッシュクラス

Constant Summary collapse

@@regex_cache =
Hash.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePatternCache

イニシャライザ



2807
2808
# File 'lib/meteor.rb', line 2807

def initialize
end

Class Method Details

.get(*args) ⇒ Object



2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
# File 'lib/meteor.rb', line 2810

def self.get(*args)
  case args.length
    when ONE
      get_1(args[0])
    when TWO
      get_2(args[0], args[1])
    else
      raise ArgumentError
  end
end

.get_1(regex) ⇒ Regexp

パターンを取得する



2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
# File 'lib/meteor.rb', line 2826

def self.get_1(regex)
  #pattern = @@regex_cache[regex]

  #

  #if pattern == nil then

  if regex.kind_of?(String) then
    if !@@regex_cache[regex.to_sym] then
      #pattern = Regexp.new(regex)

      #@@regex_cache[regex] = pattern

      if RUBY_VERSION >= RUBY_VERSION_1_9_0 then
        @@regex_cache[regex.to_sym] = Regexp.new(regex, Regexp::MULTILINE)
      else
        @@regex_cache[regex.to_sym] = Regexp.new(regex, Regexp::MULTILINE,E_UTF8)
      end
    end

    #return pattern

    @@regex_cache[regex.to_sym]
  elsif regex.kind_of?(Symbol) then
    if !@@regex_cache[regex] then
      if RUBY_VERSION >= RUBY_VERSION_1_9_0 then
        @@regex_cache[regex] = Regexp.new(regex.to_s, Regexp::MULTILINE)
      else
        @@regex_cache[regex] = Regexp.new(regex.to_s, Regexp::MULTILINE,E_UTF8)
      end
    end

    @@regex_cache[regex]
  end
end

.get_2(regex, option) ⇒ Regexp

パターンを取得する



2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
# File 'lib/meteor.rb', line 2861

def self.get_2(regex, option)
  #pattern = @@regex_cache[regex]

  #

  #if pattern == nil then

  if regex.kind_of?(String) then
    if !@@regex_cache[regex.to_sym] then
      #pattern = Regexp.new(regex)

      #@@regex_cache[regex] = pattern

      @@regex_cache[regex.to_sym] = Regexp.new(regex, option,E_UTF8)
    end

    #return pattern

    @@regex_cache[regex.to_sym]
  elsif regex.kind_of?(Symbol) then
    if !@@regex_cache[regex] then
      @@regex_cache[regex] = Regexp.new(regex.to_s, option,E_UTF8)
    end

    @@regex_cache[regex]
  end
end