Module: Nexmo::OAS::Renderer::Helpers::Summary

Defined in:
lib/nexmo/oas/renderer/helpers/summary.rb

Instance Method Summary collapse

Instance Method Details

#normalize_summary_title(summary, operation_id) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nexmo/oas/renderer/helpers/summary.rb', line 8

def normalize_summary_title(summary, operation_id)
  # return summary early if provided
  return summary unless summary.nil?

  # If the operation ID is camelCase,
  if operation_id.match?(/^[a-zA-Z]\w+(?:[A-Z]\w+){1,}/x)
    # Use the rails `.underscore` method to convert someString to some_string
    operation_id = operation_id.underscore
  end

  # Replace snake_case and kebab-case with spaces and titelize the string
  operation_id = operation_id.gsub(/(_|-)/, ' ').titleize

  # Some terms need to be capitalised all the time
  uppercase_array = %w[SMS DTMF]
  operation_id.split(' ').map do |c|
    next c.upcase if uppercase_array.include?(c.upcase)

    c
  end.join(' ')
end