Class: BSON::Regexp::Raw
Overview
Represents the raw values for the regular expression.
Instance Attribute Summary collapse
-
#options ⇒ Integer
readonly
Options The options.
-
#pattern ⇒ String
readonly
Pattern The regex pattern.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?)
Check equality of the raw bson regexp against another.
-
#as_json(*args) ⇒ Hash
Get the raw BSON regexp as JSON hash data.
-
#compile ⇒ ::Regexp
Compile the Regular expression into the native type.
-
#initialize(pattern, options = '') ⇒ Raw
constructor
Initialize the new raw regular expression.
-
#respond_to?(method, include_private = false) ⇒ Boolean
Allow automatic delegation of methods to the Regexp object returned by
compile
. -
#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ BSON::ByteBuffer
Encode the Raw Regexp object to BSON.
Methods included from JSON
Constructor Details
#initialize(pattern, options = '') ⇒ Raw
The ability to specify options as an Integer is deprecated. Please specify options as a String. The ability to pass options as as Integer will be removed in version 5.0.0.
Initialize the new raw regular expression.
156 157 158 159 |
# File 'lib/bson/regexp.rb', line 156 def initialize(pattern, = '') @pattern = pattern @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments) ⇒ Object (private)
230 231 232 233 |
# File 'lib/bson/regexp.rb', line 230 def method_missing(method, *arguments) return super unless respond_to?(method) compile.send(method, *arguments) end |
Instance Attribute Details
#options ⇒ Integer (readonly)
Returns options The options.
129 130 131 |
# File 'lib/bson/regexp.rb', line 129 def @options end |
#pattern ⇒ String (readonly)
Returns pattern The regex pattern.
126 127 128 |
# File 'lib/bson/regexp.rb', line 126 def pattern @pattern end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Check equality of the raw bson regexp against another.
221 222 223 224 225 |
# File 'lib/bson/regexp.rb', line 221 def ==(other) return false unless other.is_a?(::Regexp::Raw) pattern == other.pattern && == other. end |
#as_json(*args) ⇒ Hash
Get the raw BSON regexp as JSON hash data.
207 208 209 |
# File 'lib/bson/regexp.rb', line 207 def as_json(*args) { "$regex" => source, "$options" => } end |
#compile ⇒ ::Regexp
Compile the Regular expression into the native type.
139 140 141 |
# File 'lib/bson/regexp.rb', line 139 def compile @compiled ||= ::Regexp.new(pattern, ) end |
#respond_to?(method, include_private = false) ⇒ Boolean
Allow automatic delegation of methods to the Regexp object returned by compile
.
167 168 169 |
# File 'lib/bson/regexp.rb', line 167 def respond_to?(method, include_private = false) compile.respond_to?(method, include_private) || super end |
#to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) ⇒ 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.
Encode the Raw Regexp object to BSON.
193 194 195 196 197 |
# File 'lib/bson/regexp.rb', line 193 def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?) return compile.to_bson(buffer, validating_keys) if .is_a?(Integer) buffer.put_cstring(source) buffer.put_cstring(.chars.sort.join) end |