Module: Concordion::StringUtility

Includes:
PluralToSingularUtility, SnakeCaseUtility
Included in:
Utility
Defined in:
lib/concordion/string_utility.rb

Instance Method Summary collapse

Methods included from PluralToSingularUtility

#singular

Methods included from SnakeCaseUtility

#snake_case, #snake_cased_goldmaster_name, #snake_cased_test_name

Instance Method Details

#assignment(base) ⇒ Object



95
96
97
# File 'lib/concordion/string_utility.rb', line 95

def assignment(base)
  base.split("=")[1].strip
end

#attr_writer_method?(name) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/concordion/string_utility.rb', line 62

def attr_writer_method?(name)
  name =~ /=$/
end

#concordion_assignment(name) ⇒ Object



54
55
56
# File 'lib/concordion/string_utility.rb', line 54

def concordion_assignment(name)
  name.split("=")[0].strip
end

#concordion_method_name(name) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/concordion/string_utility.rb', line 66

def concordion_method_name(name)
  if name =~ /\(/
    base = name.split("(")[0].strip
  else
  
  
    base = name.strip
    if base =~ /\s/
    
      if base =~ /=/ && base =~ /^#/
        base = base.split("=")[1].strip
      end
      elements = base.split(/\s/)
      base = elements[0]
    end
  end

  if !has_assignment?(base)
    return base
  end
 
  if attr_writer_method?(base)
    return base if base.count("=") == 1
    return assignment(base) + "="
  end

  assignment(base)
end

#ends_in_empty_parens?(name) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/concordion/string_utility.rb', line 50

def ends_in_empty_parens?(name)
  name =~ /\(\)$/
end

#escape_single_quotes(s) ⇒ Object



99
100
101
# File 'lib/concordion/string_utility.rb', line 99

def escape_single_quotes(s)
  s.gsub(/[']/, '\\\\\\\\\'')
end

#has_arguments?(name) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/concordion/string_utility.rb', line 42

def has_arguments?(name)
  !(ends_in_empty_parens?(name) || is_direct_method_call?(name))
end

#has_assignment?(name) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/concordion/string_utility.rb', line 58

def has_assignment?(name)
  name =~ /=/
end

#is_direct_method_call?(name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/concordion/string_utility.rb', line 46

def is_direct_method_call?(name)
  name =~ /^[\w]+$/
end