Top Level Namespace
Defined in:
Method Summary
- as_array(value)
- as_hash(value)
-
extract_operation_name(query_string : String | Nil) : String | Nil
Function to extract the operation name from a GraphQL query string.
-
generate_hash(value : Type | JSON::Any) : String
This function takes any type of value (any value that can be converted to a string) as input and generates a unique SHA-256 hash value.
- normalize_any(value : Type | JSON::Any) : String
-
parse_time(input : String) : Time::Span
Converts a string in the format "1d", "1h", "30m", "45s" into a time span.
-
truncate_string(text : String | Nil, max_length : Int32 = 50, omission : String = "...") : String | Nil
This function truncates a string to a specified maximum length.
Method Detail
Function to extract the operation name from a GraphQL query string.
It searches for query
, mutation
, or subscription
followed by the operation name
and returns the name if found. Returns nil
if no operation name is detected.
Example:
Input: 'query GetUser { ... }'
Output: 'GetUser'
This function takes any type of value (any value that can be converted to a string) as input and generates a unique SHA-256 hash value.
regardless of the order of the elements, it always returns the same value
Example:
input_value1 = JSON.parse(%(
["a", 2, 1]
))
input_value2 = JSON.parse(%(
[1,2, "a"]
))
hashed_value1 = generate_hash(input_value1)
puts hashed_value1 # => "ddtt33"
hashed_value2 = generate_hash(input_value2)
puts hashed_value2 # => "ddtt33"
Converts a string in the format "1d", "1h", "30m", "45s" into a time span. Supported suffixes are:
- "s" for seconds
- "m" for minutes
- "h" for hours
- "d" for days
Example:
span = parse_time("1d") # Returns a Time::Span equivalent to 1 day
This function truncates a string to a specified maximum length. If the string exceeds the maximum length, it appends "..." to indicate truncation. Parameters:
- text: The input string to be truncated.
- max_length: The maximum length of the output string, including the "..." if truncated.
- omission: The string to append to the truncated string. Default is "...". Returns:
- A string that is either the original string (if it's shorter or equal to max_length) or the truncated version with "..." appended.