Class: MidasTouch::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/midas-touch/input.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Input

Returns a new instance of Input.



11
12
13
14
15
16
# File 'lib/midas-touch/input.rb', line 11

def initialize(name)
  self.name        = name.to_sym
  self.filters     = Array.new
  self.validations = Array.new
  @invalidate = false
end

Instance Attribute Details

#filtersObject

Returns the value of attribute filters.



8
9
10
# File 'lib/midas-touch/input.rb', line 8

def filters
  @filters
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/midas-touch/input.rb', line 4

def name
  @name
end

#validationsObject

Returns the value of attribute validations.



9
10
11
# File 'lib/midas-touch/input.rb', line 9

def validations
  @validations
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/midas-touch/input.rb', line 7

def value
  @value
end

Instance Method Details

#filter!Object



18
19
20
21
22
23
# File 'lib/midas-touch/input.rb', line 18

def filter!
  filters.each do |filter|
    self.value = filter.call(self.value)
  end
  self.value
end

#invalidate!Object



33
34
35
# File 'lib/midas-touch/input.rb', line 33

def invalidate!
  @invalidate = true
end

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/midas-touch/input.rb', line 25

def valid?
  return false if @invalidate
  validations.each do |rule|
    return false if !rule.call(self.value)
  end
  true
end