Class: Vapi::RegexReplacement
- Inherits:
-
Object
- Object
- Vapi::RegexReplacement
- Defined in:
- lib/vapi_server_sdk/types/regex_replacement.rb
Constant Summary collapse
- OMIT =
Object.new
Instance Attribute Summary collapse
-
#additional_properties ⇒ OpenStruct
readonly
Additional properties unmapped to the current class definition.
-
#options ⇒ Array<Vapi::RegexOption>
readonly
These are the options for the regex replacement.
-
#regex ⇒ String
readonly
This is the regex pattern to replace.
-
#value ⇒ String
readonly
This is the value that will replace the match.
Class Method Summary collapse
-
.from_json(json_object:) ⇒ Vapi::RegexReplacement
Deserialize a JSON object to an instance of RegexReplacement.
-
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given hash and check each fields type against the current object’s property definitions.
Instance Method Summary collapse
- #initialize(regex:, value:, options: OMIT, additional_properties: nil) ⇒ Vapi::RegexReplacement constructor
-
#to_json(*_args) ⇒ String
Serialize an instance of RegexReplacement to a JSON object.
Constructor Details
#initialize(regex:, value:, options: OMIT, additional_properties: nil) ⇒ Vapi::RegexReplacement
42 43 44 45 46 47 48 49 50 |
# File 'lib/vapi_server_sdk/types/regex_replacement.rb', line 42 def initialize(regex:, value:, options: OMIT, additional_properties: nil) @regex = regex @options = if != OMIT @value = value @additional_properties = additional_properties @_field_set = { "regex": regex, "options": , "value": value }.reject do |_k, v| v == OMIT end end |
Instance Attribute Details
#additional_properties ⇒ OpenStruct (readonly)
Returns Additional properties unmapped to the current class definition.
23 24 25 |
# File 'lib/vapi_server_sdk/types/regex_replacement.rb', line 23 def additional_properties @additional_properties end |
#options ⇒ Array<Vapi::RegexOption> (readonly)
Returns These are the options for the regex replacement. Defaults to all disabled. @default [].
19 20 21 |
# File 'lib/vapi_server_sdk/types/regex_replacement.rb', line 19 def @options end |
#regex ⇒ String (readonly)
Returns This is the regex pattern to replace. Note:
-
This works by using the ‘string.replace` method in Node.JS. Eg. `“hello
there“.replace(/hello/g, ”hi“)‘ will return `”hi there“`. Hot tip:
-
In JavaScript, escape ‘` when sending the regex pattern. Eg. `“hellosthere”`
will be sent over the wire as ‘“hellosthere”`. Send `“hello\sthere”` instead.
16 17 18 |
# File 'lib/vapi_server_sdk/types/regex_replacement.rb', line 16 def regex @regex end |
#value ⇒ String (readonly)
Returns This is the value that will replace the match.
21 22 23 |
# File 'lib/vapi_server_sdk/types/regex_replacement.rb', line 21 def value @value end |
Class Method Details
.from_json(json_object:) ⇒ Vapi::RegexReplacement
Deserialize a JSON object to an instance of RegexReplacement
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vapi_server_sdk/types/regex_replacement.rb', line 56 def self.from_json(json_object:) struct = JSON.parse(json_object, object_class: OpenStruct) parsed_json = JSON.parse(json_object) regex = parsed_json["regex"] = parsed_json["options"]&.map do |item| item = item.to_json Vapi::RegexOption.from_json(json_object: item) end value = parsed_json["value"] new( regex: regex, options: , value: value, additional_properties: struct ) end |
.validate_raw(obj:) ⇒ Void
Leveraged for Union-type generation, validate_raw attempts to parse the given
hash and check each fields type against the current object's property
definitions.
86 87 88 89 90 |
# File 'lib/vapi_server_sdk/types/regex_replacement.rb', line 86 def self.validate_raw(obj:) obj.regex.is_a?(String) != false || raise("Passed value for field obj.regex is not the expected type, validation failed.") obj.&.is_a?(Array) != false || raise("Passed value for field obj.options is not the expected type, validation failed.") obj.value.is_a?(String) != false || raise("Passed value for field obj.value is not the expected type, validation failed.") end |
Instance Method Details
#to_json(*_args) ⇒ String
Serialize an instance of RegexReplacement to a JSON object
76 77 78 |
# File 'lib/vapi_server_sdk/types/regex_replacement.rb', line 76 def to_json(*_args) @_field_set&.to_json end |