class TextInputRow
Constants
- EMAIL_REGEX
- URL_REGEX
Attributes
value[RW]
Public Class Methods
new(key, options)
click to toggle source
Calls superclass method
BaseRow::new
# File lib/project/rows/text_input_row.rb, line 10 def initialize(key, options) super @value = options.fetch(:value, nil) setup_validation listen end
Public Instance Methods
capitalize?()
click to toggle source
# File lib/project/rows/text_input_row.rb, line 66 def capitalize? options[:capitalize] || !(options[:email] || options[:secure]) end
cell_type()
click to toggle source
# File lib/project/rows/text_input_row.rb, line 70 def cell_type TextInputCell end
did_end_editing(notification)
click to toggle source
# File lib/project/rows/text_input_row.rb, line 54 def did_end_editing(notification) @value = notification.userInfo[:value] if notification.userInfo[:key] == key end
listen()
click to toggle source
# File lib/project/rows/text_input_row.rb, line 50 def listen observe('FormCellDidEndEditing', 'did_end_editing:') end
setup_validation()
click to toggle source
# File lib/project/rows/text_input_row.rb, line 20 def setup_validation if options[:required] validation_rules << lambda { |value| value && value != '' } end if options[:email] validation_rules << lambda { |value| value && value[EMAIL_REGEX] } end if options[:url] validation_rules << lambda { |value| value && value[URL_REGEX] } end if options[:format] && options[:format].is_a?(Regexp) validation_rules << lambda { |value| value && value[options[:format]] } end if options[:validate_with] && options[:validate_with].is_a?(Proc) validation_rules << options[:validate_with] end end
update_cell(cell)
click to toggle source
Calls superclass method
BaseRow#update_cell
# File lib/project/rows/text_input_row.rb, line 58 def update_cell(cell) super cell.secure = options[:secure] cell.value = value cell.capitalize = capitalize? end
valid?()
click to toggle source
# File lib/project/rows/text_input_row.rb, line 42 def valid? validation_rules.all? { |rule| rule.call(value) } end
validation_rules()
click to toggle source
# File lib/project/rows/text_input_row.rb, line 46 def validation_rules @validation_rules ||= [] end