Class: Saper::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/saper/core/type.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](type) ⇒ Saper::Type

Returns a new Type instance of a given type.

Parameters:

  • type (Symbol)

Returns:


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/saper/core/type.rb', line 7

def self.[](type)
  case type
    when Type       then type
    when :attribute then AttributeType.new
    when :document  then DocumentType.new
    when :html      then HTMLType.new
    when :json      then JSONType.new
    when :options   then OptionsType.new
    when :regex     then RegexType.new
    when :recipe    then RecipeType.new
    when :tag       then TagType.new
    when :text      then TextType.new
    when :url       then URLType.new
    when :variable  then VariableType.new
    when :xml       then XMLType.new
    when :xpath     then XPathType.new
    else raise(Errors::InvalidType, "Invalid action argument: %s" % type)
  end
end

Instance Method Details

#invalid?(value) ⇒ Boolean

Returns `true` if specified value does not match type.

Returns:

  • (Boolean)

40
41
42
# File 'lib/saper/core/type.rb', line 40

def invalid?(value)
  not valid?(value)
end

#normalize(value) ⇒ Object

Returns normalize value


28
29
30
# File 'lib/saper/core/type.rb', line 28

def normalize(value)
  value # Note: subclass may override this method.
end

#valid?(value) ⇒ Boolean

Returns `true` if specified value matches type.

Returns:

  • (Boolean)

34
35
36
# File 'lib/saper/core/type.rb', line 34

def valid?(value)
  true  # Note: subclass must override this method.
end