require "celsius" class Celsius::Transformation # # class methods # class << self attr_accessor :steps end # since a transformation can have many steps, writing a "require" for each is tedious def self.require_directory(directory) Dir.glob("#{File.expand_path(directory)}/*.rb").each do |filename| require filename end end # convenience wrapper for @steps setter to enhance readability def self.sequence(value) self.steps = value end # # instance methods # attr_accessor :source attr_accessor :target def apply(options = {}) if (@source = options[:source] ||= options[:to]).nil? raise ArgumentError, "No source given to apply transformation to!" end @target = options[:target] self.class.steps.flatten.each do |step| if step.is_a?(Class) step.new(self).call else step.call(self) end end return @target end end