Class: GodObject::PathnameConversion::ConversionToPathname

Inherits:
UserChoices::Conversion
  • Object
show all
Defined in:
lib/god_object/pathname_conversion/conversion_to_pathname.rb

Overview

This class adds the type :pathname to user-choices.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.described_by?(conversion_tag) ⇒ true, false

Decides through which tag this conversion is triggered.

The Pathname conversion is triggered by :pathname.

Parameters:

  • conversion_tag (Symbol)

    a type tag used in a choice definition

Returns:

  • (true, false)

    true, if the conversion should be triggered by the given tag, false otherwise



33
34
35
# File 'lib/god_object/pathname_conversion/conversion_to_pathname.rb', line 33

def self.described_by?(conversion_tag)
  conversion_tag == :pathname
end

Instance Method Details

#convert(value) ⇒ Pathname+

Converts the value to Pathname.

Parameters:

  • value (String, Array)

    a path

Returns:

  • (Pathname, Array<Pathname>)

    the value as Pathname or, if an Enumerable was converted, an Array of Pathnames



60
61
62
63
64
65
66
67
68
69
70
71
# 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

#descriptionString

Describes the conversion.

Returns:

  • (String)

    a description



40
41
42
# File 'lib/god_object/pathname_conversion/conversion_to_pathname.rb', line 40

def description
  "a pathname"
end

#suitable?(actual) ⇒ true, false

Answers if given value is suitable to be converted.

For Pathname conversion it needs to be a String-like or Enumerable.

Parameters:

  • actual (Object)

Returns:

  • (true, false)

    true if the given value is suitable, false otherwise



51
52
53
# 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