Class: Typero::LabelType

Inherits:
Type
  • Object
show all
Defined in:
lib/typero/type/types/label_type.rb

Constant Summary

Constants inherited from Type

Type::ERRORS, Type::OPTS, Type::OPTS_KEYS

Instance Attribute Summary

Attributes inherited from Type

#opts

Instance Method Summary collapse

Methods inherited from Type

allowed_opt?, #db_field, db_schema, #default, error, #get, #initialize, load, opts, #value

Constructor Details

This class inherits a constructor from Typero::Type

Instance Method Details

#db_schemaObject



15
16
17
18
19
# File 'lib/typero/type/types/label_type.rb', line 15

def db_schema
  [:string, {
    limit: 30
  }]
end

#setObject



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/typero/type/types/label_type.rb', line 2

def set
  value do |data|
    data
      .to_s
      .gsub(/\s+/,'-')
      .gsub(/[^\w\-]/,'')
      .gsub(/\-+/, '-')[0,30]
      .downcase
  end

  error_for(:unallowed_characters_error) unless value =~ /^[\w\-]+$/
end