Module: Glia::Errors::Naming
- Defined in:
- lib/glia/errors/naming.rb
Overview
Utilities for variable and resouce names
Constant Summary collapse
- ABBREVIATIONS =
%w[id uuid saml sip sms mms uri url].freeze
- PLURAL_ABBREVIATIONS =
%w[ids uuids uris urls].freeze
- SNAKE_CASE_REGEX =
/\A[a-z0-9]+(_[a-z0-9]+)*\z/.freeze
- HEADER_REGEX =
/\A[A-Z0-9]+[a-z0-9]*(-[A-Z0-9]+[a-zz0-9]*)*\z/.freeze
Class Method Summary collapse
- .assert_header(value) ⇒ Object
- .assert_snake_case(value) ⇒ Object
-
.humanize(value) ⇒ Object
Converts from camel_case to more human readable value first_name => “First name” site_id => “Site ID”.
Class Method Details
.assert_header(value) ⇒ Object
43 44 45 46 47 |
# File 'lib/glia/errors/naming.rb', line 43 def self.assert_header(value) return if value.to_s.match(HEADER_REGEX) raise ArgumentError, "Expected '#{value}' to be a valid header" end |
.assert_snake_case(value) ⇒ Object
35 36 37 38 39 |
# File 'lib/glia/errors/naming.rb', line 35 def self.assert_snake_case(value) return if value.to_s.match(SNAKE_CASE_REGEX) raise ArgumentError, "Expected '#{value}' to be in snake case" end |
.humanize(value) ⇒ Object
Converts from camel_case to more human readable value first_name => “First name” site_id => “Site ID”
10 11 12 13 14 |
# File 'lib/glia/errors/naming.rb', line 10 def self.humanize(value) result = value.to_s.split('_').map { |word| upcase_if_abbreviation(word) }.join(' ') upcase_first(result) end |