Class: MidasTouch::Input
- Inherits:
-
Object
- Object
- MidasTouch::Input
- Defined in:
- lib/midas-touch/input.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#validations ⇒ Object
Returns the value of attribute validations.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #filter! ⇒ Object
-
#initialize(name) ⇒ Input
constructor
A new instance of Input.
- #invalidate! ⇒ Object
- #valid? ⇒ Boolean
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
#filters ⇒ Object
Returns the value of attribute filters.
8 9 10 |
# File 'lib/midas-touch/input.rb', line 8 def filters @filters end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/midas-touch/input.rb', line 4 def name @name end |
#validations ⇒ Object
Returns the value of attribute validations.
9 10 11 |
# File 'lib/midas-touch/input.rb', line 9 def validations @validations end |
#value ⇒ Object
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
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 |