Module: Marver::StringHelper

Defined in:
lib/marver/helpers/string_helper.rb

Instance Method Summary collapse

Instance Method Details

#common_class(entity) ⇒ Object



7
8
9
# File 'lib/marver/helpers/string_helper.rb', line 7

def common_class(entity)
  constantize("Marver::#{refined(entity)}")
end

#constantize(camel_cased_word) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/marver/helpers/string_helper.rb', line 24

def constantize(camel_cased_word)
  names = camel_cased_word.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end
  constant
end

#parameterize(entity) ⇒ Object



11
12
13
# File 'lib/marver/helpers/string_helper.rb', line 11

def parameterize(entity)
  entity.split(/(?=[A-Z])/).join('_').downcase
end

#refined(name) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/marver/helpers/string_helper.rb', line 15

def refined(name)
  return "Comic" if name == 'originalIssue'
  return 'TextObject' if name == 'textObjects'
  return "KeyDate" if name == 'dates'
  return "Image" if name == 'thumbnail'
  return "Story" if name == 'stories'
  return name[0..-2].capitalize
end

#summary_class(entity) ⇒ Object



3
4
5
# File 'lib/marver/helpers/string_helper.rb', line 3

def summary_class(entity)
  constantize("Marver::Summary::#{refined(entity)}")
end