Class: YDIM::Html::Util::Validator

Inherits:
SBSM::Validator
  • Object
show all
Defined in:
lib/ydim/html/util/validator.rb

Constant Summary collapse

BOOLEAN =
[:payment_received, :deleted, :suppress_vat]
DATES =
[:date, :hosting_invoice_date]
ALLOWED_TAGS =
%{a b br div font h1 h2 h3 i img invoice li ol p pre span
strong u ul year}
ENUMS =
{
	:currency					=> [ 'CHF', 'EUR', ],
	:debitor_type			=> [ nil, 'dt_hosting', 'dt_pharmacy', 'dt_pharma',
		'dt_insurance', 'dt_info', 'dt_hospital', 'dt_health', 'dt_doctor',
     'dt_consulting' ],
	:invoice_interval => [ 'inv_12', 'inv_6', 'inv_3', 'inv_24', 'inv_m', ],
	:salutation				=>	[ nil, 'Frau', 'Herr', ],
	:status						=>	[ nil, 'is_open', 'is_due', 'is_paid', 'is_trash'],
}
EVENTS =
[ :ajax_collect_garbage, :ajax_create_item, :ajax_debitor,
:ajax_delete_autoinvoice, :ajax_delete_item, :ajax_item,
:ajax_invoice, :ajax_invoices, :ajax_status, :autoinvoice,
:create_autoinvoice, :create_debitor, :create_invoice, :debitor,
:debitors, :generate_invoice, :invoice, :invoices, :login, :logout,
:pdf, :send_invoice, :sort, :update ]
STRINGS =
[ :name, :contact, :contact_firstname, :contact_title,
:country, :description, :location, :sortvalue, :text, :unit ]
NUMERIC =
[ :unique_id, :hosting_price, :index, :precision, :price,
:quantity ]
HTML =
[ :reminder_body, :reminder_subject ]

Instance Method Summary collapse

Instance Method Details

#address_lines(value) ⇒ Object



35
36
37
# File 'lib/ydim/html/util/validator.rb', line 35

def address_lines(value)
	validate_string(value).split(/\r|\n|\r\n/)
end

#emails(value) ⇒ Object



38
39
40
41
42
# File 'lib/ydim/html/util/validator.rb', line 38

def emails(value)
  value.to_s.split(/\s*,\s*/).collect do |val| email(val) end
rescue SBSM::InvalidDataError => err
  raise SBSM::InvalidDataError.new(err.message, :emails, value)
end

#phone(value) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/ydim/html/util/validator.rb', line 43

def phone(value)
	str = value.to_s.strip
	return if(str.empty?)
	if(/^00[0-9 ]{10,}$/.match(str))
		str
	else
		raise SBSM::InvalidDataError.new(:e_invalid_phone, :phone, str)
	end
end

#validate_numeric(key, value) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/ydim/html/util/validator.rb', line 52

def validate_numeric(key, value)
  match = /-?\d*(\.\d{1,2})?/.match(value)
  if(match[1])
    match[0].to_f
  else
    match[0].to_i
  end
end