Class: Ezframe::ZipcodeType

Inherits:
TextType show all
Defined in:
lib/ezframe/column_type.rb

Overview

Japanese Zipcode type column

Instance Attribute Summary

Attributes inherited from TypeBase

#attribute, #error, #parent

Instance Method Summary collapse

Methods inherited from TextType

#db_type, #form, #value=

Methods inherited from TypeBase

#db_type, #db_value, #form, #form_html, get_class, #initialize, #key, #label, #multi_inputs?, #no_edit?, #no_view?, type_name, #value, #value=

Constructor Details

This class inherits a constructor from Ezframe::TypeBase

Instance Method Details

#normalize(val) ⇒ Object



506
507
508
509
510
511
# File 'lib/ezframe/column_type.rb', line 506

def normalize(val)
  val = super(val)
  return nil unless val
  val = val.tr("0-9", "0-9")
  return val
end

#validate(val) ⇒ Object



513
514
515
516
517
518
519
520
521
# File 'lib/ezframe/column_type.rb', line 513

def validate(val)
  super(val)
  return @error if @error
  unless /^\d{7}$/ =~ val.to_s
    @error = :invalid_value
    return @error
  end
  return nil
end

#view(opts = {}) ⇒ Object



500
501
502
503
504
# File 'lib/ezframe/column_type.rb', line 500

def view(opts = {})
  return nil if no_view? && !opts[:force]
  return "" unless @value
  return @value.to_s.gsub(/(\d{3})(\d{4})/) { "#{$1}-#{$2}" }
end