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, get_class, #initialize, #key, #label, #make_error_box, #multi_inputs?, #no_edit?, #no_view?, #type, type_name, #use_view_format, #value, #value=

Constructor Details

This class inherits a constructor from Ezframe::TypeBase

Instance Method Details

#normalize(val) ⇒ Object



721
722
723
724
725
726
# File 'lib/ezframe/column_type.rb', line 721

def normalize(val)
  val = super(val)
  return nil if !val || val.strip.empty?
  val = val.tr("0-9", "0-9")
  return val
end

#validate(val) ⇒ Object



728
729
730
731
732
733
734
735
736
737
738
# File 'lib/ezframe/column_type.rb', line 728

def validate(val)
  super(val)
  return @error if @error
  return nil if !val || val.to_s.strip.empty?

  unless /^\d{7}$/ =~ val.to_s
    @error = :invalid_value
    return @error
  end
  return nil
end

#view(opts = {}) ⇒ Object



715
716
717
718
719
# File 'lib/ezframe/column_type.rb', line 715

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