Module: WCC::Contentful::Helpers
- Extended by:
- Helpers
- Included in:
- ContentTypeIndexer, Helpers, Model, ModelBuilder
- Defined in:
- lib/wcc/contentful/helpers.rb
Instance Method Summary collapse
- #constant_from_content_type(content_type) ⇒ Object
- #content_type_from_raw(value) ⇒ Object
- #shared_prefix(string_array) ⇒ Object
Instance Method Details
#constant_from_content_type(content_type) ⇒ Object
18 19 20 |
# File 'lib/wcc/contentful/helpers.rb', line 18 def constant_from_content_type(content_type) content_type.camelize.gsub(/[^_a-zA-Z0-9]/, '_') end |
#content_type_from_raw(value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/wcc/contentful/helpers.rb', line 7 def content_type_from_raw(value) case value.dig('sys', 'type') when 'Entry' value.dig('sys', 'contentType', 'sys', 'id') when 'Asset' 'Asset' else raise ArgumentError, "Unknown content type '#{value.dig('sys', 'type') || 'null'}'" end end |
#shared_prefix(string_array) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/wcc/contentful/helpers.rb', line 22 def shared_prefix(string_array) string_array.reduce do |l, s| l = l.chop while l != s[0...l.length] l end end |