Module: BSON::Regexp::ClassMethods

Defined in:
lib/bson/regexp.rb

Overview

Since:

  • 2.0.0

Instance Method Summary collapse

Instance Method Details

#from_bson(bson) ⇒ Regexp

Deserialize the regular expression from BSON.

Parameters:

  • bson (BSON)

    The bson representing a regular expression.

Returns:

  • (Regexp)

    The decoded regular expression.

See Also:

Since:

  • 2.0.0



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/bson/regexp.rb', line 95

def from_bson(bson)
  pattern = bson.gets(NULL_BYTE).from_bson_string.chop!
  options = 0
  while (option = bson.readbyte) != 0
    case option
    when 105 # 'i'
      options |= ::Regexp::IGNORECASE
    when 109, 115 # 'm', 's'
      options |= ::Regexp::MULTILINE
    when 120 # 'x'
      options |= ::Regexp::EXTENDED
    end
  end

  new(pattern, options)
end