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



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/bson/regexp.rb', line 153

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
  Raw.new(pattern, options)
end