Module: Contentful::Support

Defined in:
lib/contentful/support.rb

Overview

Utility methods used by the contentful gem

Class Method Summary collapse

Class Method Details

.localized?(value) ⇒ Boolean

Returns true if resource is localized

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/contentful/support.rb', line 18

def localized?(value)
  return false unless value.is_a? ::Hash
  value.keys.any? { |possible_locale| Contentful::Constants::KNOWN_LOCALES.include?(possible_locale) }
end

.snakify(object) ⇒ String

Transforms CamelCase into snake_case (taken from zucker)

Parameters:

  • object (String)

    camelCaseName

Returns:

  • (String)

    snake_case_name



10
11
12
13
# File 'lib/contentful/support.rb', line 10

def snakify(object)
  snake = String(object).gsub(/(?<!^)[A-Z]/) { "_#{$&}" }
  snake.downcase
end