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

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

Overview

Pattern Cache Class (パターン・キャッシュ クラス)

Constant Summary collapse

@@regex_cache =
{}

Class Method Summary collapse

Class Method Details

.get(regex) ⇒ Regexp .get(regex, option) ⇒ Regexp

get pattern (パターンを取得する)

Overloads:

  • .get(regex) ⇒ Regexp

    Returns pattern (パターン).

    Parameters:

    • regex (String)

      regular expression (正規表現)

    Returns:

    • (Regexp)

      pattern (パターン)

  • .get(regex, option) ⇒ Regexp

    Returns pattern (パターン).

    Parameters:

    • regex (String)

      regular expression (正規表現)

    • option (Integer)

      option of Regex (オプション)

    Returns:

    • (Regexp)

      pattern (パターン)



29
30
31
32
33
34
35
36
37
38
# File 'lib/meteor/core/util/pattern_cache.rb', line 29

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

.get_one(regex) ⇒ Regexp

get pattern (パターンを取得する)

Parameters:

  • regex (String)

    regular expression (正規表現)

Returns:

  • (Regexp)

    pattern (パターン)



45
46
47
48
49
50
51
# File 'lib/meteor/core/util/pattern_cache.rb', line 45

def self.get_one(regex)
  if @@regex_cache[regex.to_sym]
    @@regex_cache[regex.to_sym]
  else
    @@regex_cache[regex.to_sym] = Regexp.new(regex, Regexp::MULTILINE)
  end
end

.get_two(regex, option) ⇒ Regexp

get pattern (パターンを取得する)

Parameters:

  • regex (String)

    (正規表現)

  • option (Integer)

    (オプション)

Returns:

  • (Regexp)

    psttern (パターン)



59
60
61
62
63
64
65
# File 'lib/meteor/core/util/pattern_cache.rb', line 59

def self.get_two(regex, option)
  if @@regex_cache[regex.to_sym]
    @@regex_cache[regex.to_sym]
  else
    @@regex_cache[regex.to_sym] = Regexp.new(regex, option)
  end
end