class Creamerscript::Sweeteners::MethodInvocation

Public Instance Methods

arguments() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 28
def arguments
  parameter_values.join(", ")
end
initializer() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 12
def initializer
  "new #{subject}(#{arguments})"
end
method_name() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 24
def method_name
  signature_keys.join("_")
end
normal_method_call() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 16
def normal_method_call
  "#{subject}.#{method_name}(#{arguments})"
end
pattern() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 4
def pattern
  /\(#{SYMBOL} #{SYMBOL}:[^\(\)]*\)/m
end
subject() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 20
def subject
  body.split.first
end
to_coffee() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 8
def to_coffee
  method_name =~ /^new/ ? initializer : normal_method_call
end

Private Instance Methods

argument_list() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 42
def argument_list
  body_without_subject.map { |arg| arg.split(":") }
end
body() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 50
def body
  source[1..-2]
end
body_without_subject() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 46
def body_without_subject
  body.split[1..-1]
end
parameter_values() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 38
def parameter_values
  argument_list.flatten.each_with_index.map { |arg, index| arg.gsub(",", "") if index.odd? }.compact
end
signature_keys() click to toggle source
# File lib/creamerscript/sweeteners/method_invocation.rb, line 34
def signature_keys
  argument_list.flatten.each_with_index.map { |arg, index| arg if index.even? }.compact
end