class GodObject::PathnameConversion::ConversionToPathname
This class adds the type :pathname to user-choices.
Public Class Methods
described_by?(conversion_tag)
click to toggle source
Decides through which tag this conversion is triggered.
The Pathname conversion is triggered by :pathname.
@param [Symbol] conversion_tag a type tag used in a choice definition @return [true, false] true, if the conversion should be triggered by
the given tag, false otherwise
# File lib/god_object/pathname_conversion/conversion_to_pathname.rb, line 33 def self.described_by?(conversion_tag) conversion_tag == :pathname end
Public Instance Methods
convert(value)
click to toggle source
Converts the value to Pathname.
@param [String, Array] value a path @return [Pathname, Array<Pathname>] the value as Pathname or, if an
Enumerable was converted, an Array of Pathnames
# File lib/god_object/pathname_conversion/conversion_to_pathname.rb, line 60 def convert(value) case value when Array pathnames = [] value.each {|path| pathnames << Pathname.new(path) } pathnames else Pathname.new(value) end end
description()
click to toggle source
Describes the conversion.
@return [String] a description
# File lib/god_object/pathname_conversion/conversion_to_pathname.rb, line 40 def description "a pathname" end
suitable?(actual)
click to toggle source
Answers if given value is suitable to be converted.
For Pathname conversion it needs to be a String-like or Enumerable.
@param [Object] actual @return [true, false] true if the given value is suitable, false
otherwise
# File lib/god_object/pathname_conversion/conversion_to_pathname.rb, line 51 def suitable?(actual) actual.respond_to?(:to_str) || actual.kind_of?(Enumerable) end