Module: BSON::Regexp
- Includes:
- JSON
- Defined in:
- lib/bson/regexp.rb
Overview
Injects behaviour for encoding and decoding regular expression values to and from raw bytes as specified by the BSON spec.
Defined Under Namespace
Modules: ClassMethods Classes: Raw
Constant Summary collapse
- BSON_TYPE =
A regular expression is type 0x0B in the BSON spec.
::String.new(11.chr, encoding: BINARY).freeze
- EXTENDED_VALUE =
Extended value constant.
'x'
- IGNORECASE_VALUE =
Ignore case constant.
'i'
- MULTILINE_VALUE =
Multiline constant.
'm'
- NEWLINE_VALUE =
Newline constant.
's'
- RUBY_MULTILINE_VALUE =
Deprecated.
Will be removed in 5.0
Ruby multiline constant.
'ms'
Instance Method Summary collapse
-
#as_json ⇒ Hash
Get the regexp as JSON hash data.
-
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
Get the regular expression as encoded BSON.
Methods included from JSON
Instance Method Details
#as_json ⇒ Hash
Get the regexp as JSON hash data.
66 67 68 |
# File 'lib/bson/regexp.rb', line 66 def as_json(*) { '$regex' => source, '$options' => } end |
#to_bson(buffer = ByteBuffer.new) ⇒ BSON::ByteBuffer
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.
Get the regular expression as encoded BSON.
89 90 91 92 |
# File 'lib/bson/regexp.rb', line 89 def to_bson(buffer = ByteBuffer.new) buffer.put_cstring(source) buffer.put_cstring() end |