Class: Onfleet::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/onfleet-ruby/util.rb

Constant Summary collapse

SPECIAL_PARSE =
{ 'skip_sms_notifications' => 'skipSMSNotifications' }.freeze

Class Method Summary collapse

Class Method Details

.constantize(class_name) ⇒ Object



7
8
9
# File 'lib/onfleet-ruby/util.rb', line 7

def self.constantize(class_name)
  Object.const_get(class_name)
end

.object_classesObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/onfleet-ruby/util.rb', line 25

def self.object_classes
  @object_classes ||= {
    'address'     => Address,
    'recipients'  => Recipient,
    'recipient'   => Recipient,
    'tasks'       => Task,
    'destination' => Destination,
    'vehicle'     => Vehicle
  }
end

.to_camel_case_lower(str) ⇒ Object



21
22
23
# File 'lib/onfleet-ruby/util.rb', line 21

def self.to_camel_case_lower(str)
  SPECIAL_PARSE[str] || str.camelize(:lower)
end

.to_underscore(key) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/onfleet-ruby/util.rb', line 11

def self.to_underscore(key)
  key
    .to_s
    .gsub(/::/, '/')
    .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
    .gsub(/([a-z\d])([A-Z])/, '\1_\2')
    .tr('-', '_')
    .downcase
end