Class: MaskableAttribute::Formatting::Formats
- Inherits:
-
Hash
- Object
- Hash
- MaskableAttribute::Formatting::Formats
- Defined in:
- lib/maskable_attribute/formatting.rb
Instance Attribute Summary collapse
-
#are_exclusive ⇒ Object
{ :format => :two_digit } { :formats => [ :upcase, :downcase ] } { :exclusive_format => { :capitalized => Proc.new{ |mask| mask.captialized } } } { :exclusive_formats =>{ :capitalized => Proc.new{ |mask| mask.captialized }, :titleized => :titleize } } { :default_format => :titleize }.
-
#default ⇒ Object
{ :format => :two_digit } { :formats => [ :upcase, :downcase ] } { :exclusive_format => { :capitalized => Proc.new{ |mask| mask.captialized } } } { :exclusive_formats =>{ :capitalized => Proc.new{ |mask| mask.captialized }, :titleized => :titleize } } { :default_format => :titleize }.
-
#has_default ⇒ Object
{ :format => :two_digit } { :formats => [ :upcase, :downcase ] } { :exclusive_format => { :capitalized => Proc.new{ |mask| mask.captialized } } } { :exclusive_formats =>{ :capitalized => Proc.new{ |mask| mask.captialized }, :titleized => :titleize } } { :default_format => :titleize }.
Instance Method Summary collapse
- #apply(format, &block) ⇒ Object
- #are_exclusive? ⇒ Boolean
- #has_default? ⇒ Boolean
-
#initialize(options = {}) ⇒ Formats
constructor
A new instance of Formats.
- #names ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Formats
Returns a new instance of Formats.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/maskable_attribute/formatting.rb', line 11 def initialize( = {}) @are_exclusive, @has_default = false, false @default = nil unless .nil? .each do |type, formats| if formats.is_a? Symbol or formats.is_a? Proc self[formats] = Format.new formats elsif formats.is_a? Array formats.each do |format| self[format] = Format.new format end else formats.each do |format, method| self[format] = Format.new method || format end end if type.to_s.include? "exclusive" @are_exclusive = true elsif type.to_s.include? "default" @has_default = true @default = self[formats] end end end end |
Instance Attribute Details
#are_exclusive ⇒ Object
{ :format => :two_digit } { :formats => [ :upcase, :downcase ] } { :exclusive_format => { :capitalized => Proc.new{ |mask| mask.captialized } } } { :exclusive_formats =>{ :capitalized => Proc.new{ |mask| mask.captialized }, :titleized => :titleize } } { :default_format => :titleize }
10 11 12 |
# File 'lib/maskable_attribute/formatting.rb', line 10 def are_exclusive @are_exclusive end |
#default ⇒ Object
{ :format => :two_digit } { :formats => [ :upcase, :downcase ] } { :exclusive_format => { :capitalized => Proc.new{ |mask| mask.captialized } } } { :exclusive_formats =>{ :capitalized => Proc.new{ |mask| mask.captialized }, :titleized => :titleize } } { :default_format => :titleize }
10 11 12 |
# File 'lib/maskable_attribute/formatting.rb', line 10 def default @default end |
#has_default ⇒ Object
{ :format => :two_digit } { :formats => [ :upcase, :downcase ] } { :exclusive_format => { :capitalized => Proc.new{ |mask| mask.captialized } } } { :exclusive_formats =>{ :capitalized => Proc.new{ |mask| mask.captialized }, :titleized => :titleize } } { :default_format => :titleize }
10 11 12 |
# File 'lib/maskable_attribute/formatting.rb', line 10 def has_default @has_default end |
Instance Method Details
#apply(format, &block) ⇒ Object
38 39 40 |
# File 'lib/maskable_attribute/formatting.rb', line 38 def apply(format, &block) fetch(format, (has_default? ? @default : Format.new)).apply yield unless yield.nil? end |
#are_exclusive? ⇒ Boolean
46 47 48 |
# File 'lib/maskable_attribute/formatting.rb', line 46 def are_exclusive? @are_exclusive end |
#has_default? ⇒ Boolean
50 51 52 |
# File 'lib/maskable_attribute/formatting.rb', line 50 def has_default? @has_default end |
#names ⇒ Object
42 43 44 |
# File 'lib/maskable_attribute/formatting.rb', line 42 def names keys end |