Namespace

Methods

Included Modules

BSON::Regexp

Injects behaviour for encoding and decoding regular expression values to and from raw bytes as specified by the BSON spec.

@see bsonspec.org/#/specification

@since 2.0.0

Constants

BSON_TYPE

A regular expression is type 0x0B in the BSON spec.

@since 2.0.0

Public Instance Methods

as_json(*args) click to toggle source

Get the regexp as JSON hash data.

@example Get the regexp as a JSON hash.

regexp.as_json

@return [ Hash ] The regexp as a JSON hash.

@since 2.0.0

# File lib/bson/regexp.rb, line 39
def as_json(*args)
  { "$regex" => source, "$options" => bson_options }
end
to_bson(encoded = ''.force_encoding(BINARY)) click to toggle source

Get the regular expression as encoded BSON.

@example Get the regular expression as encoded BSON.

%r{\d+}.to_bson

@note From the BSON spec: The first cstring is the regex pattern,

the second is the regex options string. Options are identified
by characters, which must be stored in alphabetical order.
Valid options are 'i' for case insensitive matching,
'm' for multiline matching, 'x' for verbose mode,
'l' to make \w, \W, etc. locale dependent,
's' for dotall mode ('.' matches everything),
and 'u' to make \w, \W, etc. match unicode.

@return [ String ] The encoded string.

@see bsonspec.org/#/specification

@since 2.0.0

# File lib/bson/regexp.rb, line 62
def to_bson(encoded = ''.force_encoding(BINARY))
  source.to_bson_cstring(encoded)
  bson_options.to_bson_cstring(encoded)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.