class Poleica::Converters::Coercive

The Coercive converter, it tries to coerce the polei

Constants

COMPATIBLE_TYPES
TYPE_RETURNED_BY_METHOD

TODO: Think about another way of declare return types

Attributes

polei[R]

Public Class Methods

new(polei) click to toggle source
# File lib/poleica/converters/coercive.rb, line 20
def initialize(polei)
  @polei = polei
end

Private Instance Methods

coerce(method, options) click to toggle source
# File lib/poleica/converters/coercive.rb, line 40
def coerce(method, options)
  conversion_hash = find_next_converter_by_method(method)
  return nil unless conversion_hash
  next_method     = conversion_hash.keys.first
  polei.send(next_method.to_sym, options)
end
find_next_converter_by_method(origin_method) click to toggle source

Find the next method and converter needed to execute a given conversion @param <Symbol/String> the given method conversion name @return [Hash<Symbol, Converter>] the next method needed to execute

# File lib/poleica/converters/coercive.rb, line 51
def find_next_converter_by_method(origin_method)
  next_converters_by_method.find do |converter_by_method|
    conv = converter_by_method.values.first
    conv.method_defined?(origin_method.to_sym)
  end
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/poleica/converters/coercive.rb, line 26
def method_missing(method, *args, &block)
  extension, options = Utils.extract_extension_and_options(method, args)
  return try_convert(method, options) if extension
  super
end
try_convert(method, options = {}) click to toggle source
# File lib/poleica/converters/coercive.rb, line 32
def try_convert(method, options = {})
  coerced_path = coerce(method, options)
  return nil unless coerced_path
  converted_path = Poleica.new(coerced_path).send(method.to_sym, options)
  File.delete(coerced_path)
  converted_path
end