Class: ParsableHash::Strategy::ConverterLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/parsable_hash/strategy/converter_loader.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @name      = name.to_s
  self.klass = options.fetch(:converter) { load_from_name }
end

Instance Attribute Details

#klassObject

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