Class: Audrey::Object::Scalar::String::Field

Inherits:
Custom::Field show all
Defined in:
lib/audrey.rb

Overview

Audrey::Object::Scalar::String::Field

Instance Attribute Summary collapse

Attributes inherited from Custom::Field

#auto, #clss, #graph, #name, #publish, #read, #required, #write

Instance Method Summary collapse

Methods inherited from Custom::Field

#add_to_class, #auto_add

Constructor Details

#initialize(*opts) ⇒ Field


initialize



2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
# File 'lib/audrey.rb', line 2345

def initialize(*opts)
  super(*opts)
  @fclass = String
  
  # normalize
  @collapse = false
  @downcase = false
  @upcase = false
  
  # checks
  @min_length = nil
  @max_length = nil
  @hascontent = false
end

Instance Attribute Details

#collapseObject

Returns the value of attribute collapse.



2334
2335
2336
# File 'lib/audrey.rb', line 2334

def collapse
  @collapse
end

#downcaseObject

Returns the value of attribute downcase.



2335
2336
2337
# File 'lib/audrey.rb', line 2335

def downcase
  @downcase
end

#fclassObject (readonly)

Returns the value of attribute fclass.



2340
2341
2342
# File 'lib/audrey.rb', line 2340

def fclass
  @fclass
end

#hascontentObject

Returns the value of attribute hascontent.



2339
2340
2341
# File 'lib/audrey.rb', line 2339

def hascontent
  @hascontent
end

#max_lengthObject

Returns the value of attribute max_length.



2338
2339
2340
# File 'lib/audrey.rb', line 2338

def max_length
  @max_length
end

#min_lengthObject

Returns the value of attribute min_length.



2337
2338
2339
# File 'lib/audrey.rb', line 2337

def min_length
  @min_length
end

#upcaseObject

Returns the value of attribute upcase.



2336
2337
2338
# File 'lib/audrey.rb', line 2336

def upcase
  @upcase
end

Instance Method Details

#base_checks(xeme, fieldname, val) ⇒ Object


base_checks



2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
# File 'lib/audrey.rb', line 2410

def base_checks(xeme, fieldname, val)
  # $tm.hrm
  
  # min_length
  if @min_length
    if val.length < @min_length
      xeme.error('min-length') do |msg|
        msg['val'] = val
        msg['min-length'] = @min_length
      end
    end
  end
  
  # max_length
  if @max_length
    if val.length > @max_length
      xeme.error('max-length') do |msg|
        msg['val'] = val
        msg['max-length'] = @max_length
      end
    end
  end
  
  # hascontent
  if @hascontent
    if not val.match(/\S/mu)
      xeme.error('hascontent') do |msg|
        msg['val'] = val
      end
    end
  end
end

#has_checks?Boolean


has_checks?

Returns:



2397
2398
2399
2400
2401
# File 'lib/audrey.rb', line 2397

def has_checks?
  @min_length and return true
  @max_length and return true
  @hascontent and return true
end

#normalize(val) ⇒ Object


normalize



2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
# File 'lib/audrey.rb', line 2367

def normalize(val)
  # early exit
  if not val.is_a?(String)
    return
  end
  
  # collapse
  if @collapse
    val.strip!
    val.gsub!(/[^[:graph:]]+/mu, ' ')
  end
  
  # downcase, upcase
  if @downcase
    val.downcase!
  elsif @upcase
    val.upcase!
  end
  
  # return
  return val
end