Module: Typekit::Helper

Defined in:
lib/typekit/helper.rb

Constant Summary collapse

Error =
Class.new(Typekit::Error)

Class Method Summary collapse

Class Method Details

.build_query(parameters) ⇒ Object



21
22
23
# File 'lib/typekit/helper.rb', line 21

def self.build_query(parameters)
  Rack::Utils.build_nested_query(prepare_parameters(parameters))
end

.member_action?(action) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
# File 'lib/typekit/helper.rb', line 7

def self.member_action?(action)
  if Typekit.member_actions.include?(action)
    true
  elsif Typekit.collection_actions.include?(action)
    false
  else
    raise Error, 'Unknown action'
  end
end

.pluralize(name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/typekit/helper.rb', line 25

def self.pluralize(name)
  case name
  when /^.*s$/
    name
  when /^(?<root>.*)y$/
    "#{ Regexp.last_match(:root) }ies"
  else
    "#{ name }s"
  end
end

.singularize(name) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/typekit/helper.rb', line 36

def self.singularize(name)
  case name
  when /^(?<root>.*)ies$/
    "#{ Regexp.last_match(:root) }y"
  when /^(?<root>.*)s$/
    Regexp.last_match(:root)
  else
    name
  end
end

.translate_action(action) ⇒ Object



17
18
19
# File 'lib/typekit/helper.rb', line 17

def self.translate_action(action)
  Typekit.action_dictionary[action] or raise Error, 'Unknown action'
end