Class: Vapi::RegexReplacement

Inherits:
Object
  • Object
show all
Defined in:
lib/vapi_server_sdk/types/regex_replacement.rb

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regex:, value:, options: OMIT, additional_properties: nil) ⇒ Vapi::RegexReplacement

Parameters:

  • regex (String) —

    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. "hello\sthere" will be sent over the wire as "hellosthere". Send "hello\\sthere" instead.
  • options (Array<Vapi::RegexOption>) (defaults to: OMIT) —

    These are the options for the regex replacement. Defaults to all disabled. @default []

  • value (String) —

    This is the value that will replace the match.

  • additional_properties (OpenStruct) (defaults to: nil) —

    Additional properties unmapped to the current class definition



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 = options if options != OMIT
  @value = value
  @additional_properties = additional_properties
  @_field_set = { "regex": regex, "options": 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.

Returns:

  • (OpenStruct) —

    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 [].

Returns:

  • (Array<Vapi::RegexOption>) —

    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
  @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. "hello\sthere" will be sent over the wire as "hellosthere". Send "hello\\sthere" instead.

Returns:

  • (String) —

    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. "hello\sthere" 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.

Returns:

  • (String) —

    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

Parameters:

  • json_object (String)

Returns:



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"]
  options = 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: 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.

Parameters:

  • obj (Object)

Returns:

  • (Void)


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.options&.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

Returns:

  • (String)


76
77
78
# File 'lib/vapi_server_sdk/types/regex_replacement.rb', line 76

def to_json(*_args)
  @_field_set&.to_json
end