Class: ParsableHash::Strategy::ConverterLoader
- Inherits:
-
Object
- Object
- ParsableHash::Strategy::ConverterLoader
- Defined in:
- lib/parsable_hash/strategy/converter_loader.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
Class Method Summary collapse
Instance Method Summary collapse
- #call(val) ⇒ Object
-
#initialize(name, options = {}) ⇒ ConverterLoader
constructor
A new instance of ConverterLoader.
Constructor Details
#initialize(name, options = {}) ⇒ ConverterLoader
Returns a new instance of ConverterLoader.
22 23 24 25 |
# File 'lib/parsable_hash/strategy/converter_loader.rb', line 22 def initialize(name, = {}) @name = name.to_s self.klass = .fetch(:converter) { load_from_name } end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
20 21 22 |
# File 'lib/parsable_hash/strategy/converter_loader.rb', line 20 def klass @klass end |
Class Method Details
.from_class(klass) ⇒ Object
16 17 18 |
# File 'lib/parsable_hash/strategy/converter_loader.rb', line 16 def self.from_class(klass) new(nil, :converter => klass) end |
.from_name(name) ⇒ Object
12 13 14 |
# File 'lib/parsable_hash/strategy/converter_loader.rb', line 12 def self.from_name(name) new(name) end |
.from_value(value) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/parsable_hash/strategy/converter_loader.rb', line 4 def self.from_value(value) if value.is_a? Class from_class(value) else from_name(value) end end |
Instance Method Details
#call(val) ⇒ Object
27 28 29 |
# File 'lib/parsable_hash/strategy/converter_loader.rb', line 27 def call(val) klass.new(val).call end |