Module: Walt::Operation

Defined in:
lib/walt/operation/base.rb,
lib/walt/operation/fade.rb,
lib/walt/operation/move.rb,
lib/walt/operation/scale.rb,
lib/walt/operation/rotate.rb

Defined Under Namespace

Classes: Base, FadeOperation, MoveOperation, RotateOperation, ScaleOperation

Class Method Summary collapse

Class Method Details

.for(hash) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/walt/operation/base.rb', line 36

def for(hash)
  # Check classes in module for corresponding operation
  type = hash[:type] || hash["type"]

  # Check for the form {operation_type: :id}
  if !type
    type = (hash.keys.map(&:to_s) | self.operation_types)[0]
    hash[:id] = (hash[type] || hash[type.to_sym])
    hash[:type] = type
  end

  if type.is_a?(Symbol) || type.is_a?(String)
    string = "#{type.to_s.downcase}_operation".camelize
    if not const_defined? string
      raise "Invalid Operation value for operation #{hash.inspect}. Create a class called #{string}."
    end
    return Walt::Operation.const_get(string).new(hash)
  end

  self.new(hash)
end

.operation_typesObject



58
59
60
# File 'lib/walt/operation/base.rb', line 58

def operation_types
  Walt::Operation.constants(false).select { |constant_name| constant_name =~ /Operation$/ }.collect! { |op| op.to_s.gsub("Operation", "").underscore }
end