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



2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
# File 'lib/audrey.rb', line 2338

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

Instance Attribute Details

#aclassObject (readonly)

Returns the value of attribute aclass.



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

def aclass
  @aclass
end

#collapseObject

Returns the value of attribute collapse.



2327
2328
2329
# File 'lib/audrey.rb', line 2327

def collapse
  @collapse
end

#downcaseObject

Returns the value of attribute downcase.



2328
2329
2330
# File 'lib/audrey.rb', line 2328

def downcase
  @downcase
end

#hascontentObject

Returns the value of attribute hascontent.



2332
2333
2334
# File 'lib/audrey.rb', line 2332

def hascontent
  @hascontent
end

#max_lengthObject

Returns the value of attribute max_length.



2331
2332
2333
# File 'lib/audrey.rb', line 2331

def max_length
  @max_length
end

#min_lengthObject

Returns the value of attribute min_length.



2330
2331
2332
# File 'lib/audrey.rb', line 2330

def min_length
  @min_length
end

#upcaseObject

Returns the value of attribute upcase.



2329
2330
2331
# File 'lib/audrey.rb', line 2329

def upcase
  @upcase
end

Instance Method Details

#base_checks(xeme, fieldname, val) ⇒ Object


base_checks



2403
2404
2405
2406
2407
2408
2409
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
# File 'lib/audrey.rb', line 2403

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:



2390
2391
2392
2393
2394
# File 'lib/audrey.rb', line 2390

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

#normalize(val) ⇒ Object


normalize



2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
# File 'lib/audrey.rb', line 2360

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