Class: Peachy::MethodName

Inherits:
Object
  • Object
show all
Includes:
StringStyler
Defined in:
lib/peachy/method_name.rb

Instance Method Summary collapse

Methods included from StringStyler::Stripper

#strip_underscores_and_upcase

Constructor Details

#initialize(method_name) ⇒ MethodName

Returns a new instance of MethodName.



7
8
9
# File 'lib/peachy/method_name.rb', line 7

def initialize method_name
  @method_name = method_name.to_s
end

Instance Method Details

#as_xpathObject



18
19
20
# File 'lib/peachy/method_name.rb', line 18

def as_xpath 
  variations.map {|variation| "./#{variation}" } * '|'
end

#check_for_conventionObject

Checks whether the method name is in the accepted convention, raising a MethodNotInRubyConvention if it’s not. This check does not allow method names to have question marks, exclamation marks or numbers, however.



25
26
27
# File 'lib/peachy/method_name.rb', line 25

def check_for_convention
  raise MethodNotInRubyConvention.new(self) unless matches_convention?
end

#variationsObject

Returns an array of distinct valid variations in the method name. The valid varations are the underlying method name, plus all variations provided by methods defined in the StringStyler module.



14
15
16
# File 'lib/peachy/method_name.rb', line 14

def variations
  variation_methods.inject([]) {|array, method| array << send(method)}.uniq
end