Class: Saper::Arguments::Recipe

Inherits:
Saper::Argument show all
Defined in:
lib/saper/arguments/recipe.rb

Instance Method Summary collapse

Methods inherited from Saper::Argument

[], #action, exists?, inherited, #initialize, #mandatory?, new, #optional?, #set, subclasses, type, #value

Constructor Details

This class inherits a constructor from Saper::Argument

Instance Method Details

#normalize(value) ⇒ Object

TODO:

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/saper/arguments/recipe.rb', line 11

def normalize(value)
  if value.is_a?(Saper::Recipe)
    return value
  end
  if value.is_a?(Symbol)
    value = value.to_s
  end
  if value.is_a?(Numeric)
    value = value.to_s
  end
  unless value.is_a?(String)
    raise Errors::InvalidArgument, value
  end
  if action.nil?
    raise Errors::NamespaceMissing
  end
  if action.namespace.nil?
    raise Errors::NamespaceMissing
  end
  unless action.namespace[value]
    raise Errors::ActionNotFound, value
  end
  action.namespace[value]
end

#serializeObject

TODO:

37
38
39
# File 'lib/saper/arguments/recipe.rb', line 37

def serialize
  value.id
end

#to_stringObject

TODO:

42
43
44
# File 'lib/saper/arguments/recipe.rb', line 42

def to_string
  value.id.inspect
end

#valid?(value) ⇒ Boolean

TODO:

Returns:

  • (Boolean)

6
7
8
# File 'lib/saper/arguments/recipe.rb', line 6

def valid?(value)
  value.is_a?(Symbol) || value.is_a?(String) || value.is_a?(Numeric) || value.is_a?(Saper::Recipe)
end