Class: GodObject::PathnameConversion::ConversionToPathname
- Inherits:
-
UserChoices::Conversion
- Object
- UserChoices::Conversion
- GodObject::PathnameConversion::ConversionToPathname
- 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
-
.described_by?(conversion_tag) ⇒ true, false
Decides through which tag this conversion is triggered.
Instance Method Summary collapse
-
#convert(value) ⇒ Pathname+
Converts the value to Pathname.
-
#description ⇒ String
Describes the conversion.
-
#suitable?(actual) ⇒ true, false
Answers if given value is suitable to be converted.
Class Method Details
.described_by?(conversion_tag) ⇒ true, false
Decides through which tag this conversion is triggered.
The Pathname conversion is triggered by :pathname.
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.
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 |
#description ⇒ String
Describes the conversion.
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.
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 |