Решение на Четвърта задача от Кирчо Кирев

Обратно към всички решения

Към профила на Кирчо Кирев

Резултати

  • 5 точки от тестове
  • 0 бонус точки
  • 5 точки общо
  • 37 успешни тест(а)
  • 4 неуспешни тест(а)

Код

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_username
elsif preserve_email_hostname then preserve_hostname
else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
@text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}(@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3})/,
'[FILTERED]' + '\\1')
end
def partially_preserve_username
@text.gsub(/([a-zA-Z0-9][-\w\+\.]{,200})(@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
preserve_country_code
else
@text.gsub(/(?<![\+A-Za-z0-9])(0(?=[1-9])|(00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '[PHONE]')
end
end
def preserve_country_code
@text = @text.gsub(/(?<![\+A-Za-z0-9])((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/,
'\\1' + " [FILTERED]")
@text.gsub(/(?<![\+A-Za-z0-9])0(?=[1-9])([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
end
end
class Validations
class << self
def email?(value)
/\A[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def phone?(value)
/\A(0(?=[1-9])|(00|\+)[1-9]\d{,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time) and
value[-1] !~ / |T/
end
end
end

Лог от изпълнението

...F.....F..F......F.....................

Failures:

  1) PrivacyFilter does not filter invalid emails
     Failure/Error: filter(text_with_invalid_emails).should eq text_with_invalid_emails
       
       expected: "Contact me here: _invalid@email.com"
            got: "Contact me here: _[EMAIL]"
       
       (compared using ==)
     # /tmp/d20130203-23049-1esjd1w/spec.rb:52:in `block (3 levels) in <top (required)>'
     # /tmp/d20130203-23049-1esjd1w/spec.rb:46:in `each'
     # /tmp/d20130203-23049-1esjd1w/spec.rb:46:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) PrivacyFilter does not filter invalid phone numbers
     Failure/Error: filter(text).should eq filtered
       
       expected: "Reach me at: 0885123"
            got: "Reach me at: [PHONE]"
       
       (compared using ==)
     # /tmp/d20130203-23049-1esjd1w/spec.rb:96:in `block (3 levels) in <top (required)>'
     # /tmp/d20130203-23049-1esjd1w/spec.rb:95:in `each'
     # /tmp/d20130203-23049-1esjd1w/spec.rb:95:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) PrivacyFilter allows country code to be preserved for internationally-formatted phone numbers
     Failure/Error: filter.filtered.should eq filtered
       
       expected: "Phone: [PHONE] !"
            got: "Phone: 0 88 255-512 12 !"
       
       (compared using ==)
     # /tmp/d20130203-23049-1esjd1w/spec.rb:132:in `block (3 levels) in <top (required)>'
     # /tmp/d20130203-23049-1esjd1w/spec.rb:129:in `each'
     # /tmp/d20130203-23049-1esjd1w/spec.rb:129:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Validations can validate more complex phone numbers
     Failure/Error: Validations.phone?(phone).should be(valid)
       
       expected #<FalseClass:0> => false
            got #<TrueClass:2> => true
       
       Compared using equal?, which compares object identity,
       but expected and actual are not the same object. Use
       'actual.should eq(expected)' if you don't care about
       object identity in this example.
     # /tmp/d20130203-23049-1esjd1w/spec.rb:210:in `block (3 levels) in <top (required)>'
     # /tmp/d20130203-23049-1esjd1w/spec.rb:209:in `each'
     # /tmp/d20130203-23049-1esjd1w/spec.rb:209:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.04728 seconds
41 examples, 4 failures

Failed examples:

rspec /tmp/d20130203-23049-1esjd1w/spec.rb:44 # PrivacyFilter does not filter invalid emails
rspec /tmp/d20130203-23049-1esjd1w/spec.rb:89 # PrivacyFilter does not filter invalid phone numbers
rspec /tmp/d20130203-23049-1esjd1w/spec.rb:122 # PrivacyFilter allows country code to be preserved for internationally-formatted phone numbers
rspec /tmp/d20130203-23049-1esjd1w/spec.rb:184 # Validations can validate more complex phone numbers

История (11 версии и 0 коментара)

Кирчо обнови решението на 27.11.2012 17:25 (преди над 11 години)

+module FilterEmail
+ def filter_email
+ if partially_preserve_email_username then partially_preserve_email
+ elsif preserve_email_hostname then preserve_hostname
+ else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
+ end
+ end
+
+ def preserve_hostname
+ @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
+ '[FILTERED]' + $1
+ end
+ end
+
+ def partially_preserve_email
+ @text.gsub(/([a-zA-Z0-9][-\w\+\.]{,199})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
+ if $1.length < 6
+ '[FILTERED]' + $2
+ else
+ $1[0,3] + '[FILTERED]' + $2
+ end
+ end
+ end
+end
+
+module FilterPhone
+ def filter_phone
+ if preserve_phone_country_code
+ @text = @text.gsub(/((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/) { |matched| $1 + " [FILTERED]"}
+ end
+ @text.gsub(/\b0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
+ end
+end
+
+class PrivacyFilter
+ include FilterEmail, FilterPhone
+ attr_accessor :preserve_phone_country_code,
+ :preserve_email_hostname,
+ :partially_preserve_email_username
+
+ def initialize(text)
+ @text = text
+ end
+
+ def filtered
+ @text = filter_email
+ @text = filter_phone
+
+ @text
+ end
+end
+
+class Validations
+ class << self
+ def email?(value)
+ value_parts = value.split('@')
+ name, hostname = value_parts
+ value_parts.length == 2 and hostname?(hostname) and
+ /\A[a-zA-Z0-9][-\w\+\.]{,199}\z/.match(name) != nil
+ end
+
+ def phone?(value)
+ /\A(0|(00|\+)[1-9]\d)([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
+ end
+
+ def hostname?(value)
+ /\A([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
+ end
+
+ def ip_address?(value)
+ /\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
+ end
+
+ def number?(value)
+ /\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
+ end
+
+ def integer?(value)
+ /\A-?(0|[1-9]\d*)\z/.match(value) != nil
+ end
+
+ def date?(value)
+ /\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
+ end
+
+ def time?(value)
+ /\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
+ end
+
+ def date_time?(value)
+ value_parts = value.split(/ |T/)
+ date, time = value_parts
+ value_parts.length == 2 and date?(date) and time?(time)
+ end
+ end
+end

Кирчо обнови решението на 27.11.2012 17:29 (преди над 11 години)

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_email
elsif preserve_email_hostname then preserve_hostname
else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
@text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
'[FILTERED]' + $1
end
end
def partially_preserve_email
@text.gsub(/([a-zA-Z0-9][-\w\+\.]{,199})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
@text = @text.gsub(/((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/) { |matched| $1 + " [FILTERED]"}
end
@text.gsub(/\b0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
@text
end
end
class Validations
class << self
def email?(value)
value_parts = value.split('@')
name, hostname = value_parts
value_parts.length == 2 and hostname?(hostname) and
/\A[a-zA-Z0-9][-\w\+\.]{,199}\z/.match(name) != nil
end
def phone?(value)
- /\A(0|(00|\+)[1-9]\d)([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
+ /\A(0|(00|\+)[1-9]\d)([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time)
end
end
end

Кирчо обнови решението на 27.11.2012 21:44 (преди над 11 години)

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_email
elsif preserve_email_hostname then preserve_hostname
else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
- @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
- '[FILTERED]' + $1
- end
+ @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/,
+ '[FILTERED]' + '\\1')
end
def partially_preserve_email
@text.gsub(/([a-zA-Z0-9][-\w\+\.]{,199})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
- @text = @text.gsub(/((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/) { |matched| $1 + " [FILTERED]"}
+ @text = @text.gsub(/((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '\\1' + " [FILTERED]")
end
- @text.gsub(/\b0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
+ @text.gsub(/\B0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
@text
end
end
class Validations
class << self
def email?(value)
value_parts = value.split('@')
name, hostname = value_parts
value_parts.length == 2 and hostname?(hostname) and
/\A[a-zA-Z0-9][-\w\+\.]{,199}\z/.match(name) != nil
end
def phone?(value)
/\A(0|(00|\+)[1-9]\d)([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time)
end
end
end

Кирчо обнови решението на 27.11.2012 22:40 (преди над 11 години)

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_email
elsif preserve_email_hostname then preserve_hostname
else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
@text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/,
'[FILTERED]' + '\\1')
end
def partially_preserve_email
@text.gsub(/([a-zA-Z0-9][-\w\+\.]{,199})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
@text = @text.gsub(/((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '\\1' + " [FILTERED]")
end
- @text.gsub(/\B0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
+ @text.gsub(/(?<=\s)0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
@text
end
end
class Validations
class << self
def email?(value)
value_parts = value.split('@')
name, hostname = value_parts
value_parts.length == 2 and hostname?(hostname) and
/\A[a-zA-Z0-9][-\w\+\.]{,199}\z/.match(name) != nil
end
def phone?(value)
/\A(0|(00|\+)[1-9]\d)([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time)
end
end
end

Кирчо обнови решението на 27.11.2012 23:16 (преди над 11 години)

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_email
elsif preserve_email_hostname then preserve_hostname
else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
@text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/,
'[FILTERED]' + '\\1')
end
def partially_preserve_email
@text.gsub(/([a-zA-Z0-9][-\w\+\.]{,199})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
@text = @text.gsub(/((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '\\1' + " [FILTERED]")
end
- @text.gsub(/(?<=\s)0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
+ @text.gsub(/(?<=[^\+A-Za-z0-9])0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
@text
end
end
class Validations
class << self
def email?(value)
value_parts = value.split('@')
name, hostname = value_parts
value_parts.length == 2 and hostname?(hostname) and
/\A[a-zA-Z0-9][-\w\+\.]{,199}\z/.match(name) != nil
end
def phone?(value)
/\A(0|(00|\+)[1-9]\d)([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time)
end
end
end

Кирчо обнови решението на 28.11.2012 10:28 (преди над 11 години)

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_email
elsif preserve_email_hostname then preserve_hostname
else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
@text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/,
'[FILTERED]' + '\\1')
end
def partially_preserve_email
@text.gsub(/([a-zA-Z0-9][-\w\+\.]{,199})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
@text = @text.gsub(/((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '\\1' + " [FILTERED]")
end
@text.gsub(/(?<=[^\+A-Za-z0-9])0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
@text
end
end
class Validations
class << self
def email?(value)
value_parts = value.split('@')
name, hostname = value_parts
- value_parts.length == 2 and hostname?(hostname) and
+ value_parts.length == 2 and hostname?(hostname) and value[-1] !~ /@/ and
/\A[a-zA-Z0-9][-\w\+\.]{,199}\z/.match(name) != nil
end
def phone?(value)
/\A(0|(00|\+)[1-9]\d)([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
- value_parts.length == 2 and date?(date) and time?(time)
+ value_parts.length == 2 and date?(date) and time?(time) and
+ value[-1] !~ / |T/
end
end
end

Кирчо обнови решението на 28.11.2012 14:52 (преди над 11 години)

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_email
elsif preserve_email_hostname then preserve_hostname
else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
@text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/,
'[FILTERED]' + '\\1')
end
def partially_preserve_email
@text.gsub(/([a-zA-Z0-9][-\w\+\.]{,199})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
- @text = @text.gsub(/((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '\\1' + " [FILTERED]")
+ @text = @text.gsub(/(?<![\+A-Za-z0-9])((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/,
+ '\\1' + " [FILTERED]")
end
- @text.gsub(/(?<=[^\+A-Za-z0-9])0([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
+ @text.gsub(/(?<![\+A-Za-z0-9])(0(?=[1-9])|(00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
@text
end
end
class Validations
class << self
def email?(value)
- value_parts = value.split('@')
- name, hostname = value_parts
- value_parts.length == 2 and hostname?(hostname) and value[-1] !~ /@/ and
- /\A[a-zA-Z0-9][-\w\+\.]{,199}\z/.match(name) != nil
+ /\A[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def phone?(value)
- /\A(0|(00|\+)[1-9]\d)([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
+ /\A(0(?=[1-9])|(00|\+)[1-9]\d{,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
- /\A([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
+ /\A([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time) and
value[-1] !~ / |T/
end
end
end

Кирчо обнови решението на 28.11.2012 15:06 (преди над 11 години)

module FilterEmail
def filter_email
- if partially_preserve_email_username then partially_preserve_email
+ if partially_preserve_email_username then partially_preserve_username
elsif preserve_email_hostname then preserve_hostname
- else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
+ else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
- @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,199}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/,
+ @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/,
'[FILTERED]' + '\\1')
end
- def partially_preserve_email
- @text.gsub(/([a-zA-Z0-9][-\w\+\.]{,199})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
+ def partially_preserve_username
+ @text.gsub(/([a-zA-Z0-9][-\w\+\.]{,200})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
- @text = @text.gsub(/(?<![\+A-Za-z0-9])((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/,
- '\\1' + " [FILTERED]")
+ preserve_country_code
+ else
+ @text.gsub(/(?<![\+A-Za-z0-9])(0(?=[1-9])|(00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '[PHONE]')
end
- @text.gsub(/(?<![\+A-Za-z0-9])(0(?=[1-9])|(00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '[PHONE]')
+ end
+
+ def preserve_country_code
+ @text = @text.gsub(/(?<![\+A-Za-z0-9])((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/,
+ '\\1' + " [FILTERED]")
+ @text.gsub(/(?<=[^\+A-Za-z0-9])0(?=[1-9])([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
@text
end
end
class Validations
class << self
def email?(value)
/\A[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def phone?(value)
/\A(0(?=[1-9])|(00|\+)[1-9]\d{,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time) and
value[-1] !~ / |T/
end
end
end

Кирчо обнови решението на 28.11.2012 15:10 (преди над 11 години)

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_username
elsif preserve_email_hostname then preserve_hostname
- else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
+ else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
- @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/,
+ @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}(@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3})/,
'[FILTERED]' + '\\1')
end
def partially_preserve_username
- @text.gsub(/([a-zA-Z0-9][-\w\+\.]{,200})(@([a-zA-Z0-9][-a-zA-Z0-9]{,61}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
+ @text.gsub(/([a-zA-Z0-9][-\w\+\.]{,200})(@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
preserve_country_code
else
@text.gsub(/(?<![\+A-Za-z0-9])(0(?=[1-9])|(00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '[PHONE]')
end
end
def preserve_country_code
@text = @text.gsub(/(?<![\+A-Za-z0-9])((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/,
'\\1' + " [FILTERED]")
@text.gsub(/(?<=[^\+A-Za-z0-9])0(?=[1-9])([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
@text
end
end
class Validations
class << self
def email?(value)
/\A[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def phone?(value)
/\A(0(?=[1-9])|(00|\+)[1-9]\d{,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time) and
value[-1] !~ / |T/
end
end
end

Кирчо обнови решението на 28.11.2012 15:37 (преди над 11 години)

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_username
elsif preserve_email_hostname then preserve_hostname
else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
@text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}(@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3})/,
'[FILTERED]' + '\\1')
end
def partially_preserve_username
@text.gsub(/([a-zA-Z0-9][-\w\+\.]{,200})(@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
preserve_country_code
else
@text.gsub(/(?<![\+A-Za-z0-9])(0(?=[1-9])|(00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '[PHONE]')
end
end
def preserve_country_code
@text = @text.gsub(/(?<![\+A-Za-z0-9])((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/,
'\\1' + " [FILTERED]")
- @text.gsub(/(?<=[^\+A-Za-z0-9])0(?=[1-9])([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
+ @text.gsub(/(?<![\+A-Za-z0-9])0(?=[1-9])([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
@text
end
end
class Validations
class << self
def email?(value)
/\A[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def phone?(value)
/\A(0(?=[1-9])|(00|\+)[1-9]\d{,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time) and
value[-1] !~ / |T/
end
end
end

Кирчо обнови решението на 28.11.2012 15:41 (преди над 11 години)

module FilterEmail
def filter_email
if partially_preserve_email_username then partially_preserve_username
elsif preserve_email_hostname then preserve_hostname
else @text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}/, '[EMAIL]')
end
end
def preserve_hostname
@text.gsub(/[a-zA-Z0-9][-\w\+\.]{,200}(@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3})/,
'[FILTERED]' + '\\1')
end
def partially_preserve_username
@text.gsub(/([a-zA-Z0-9][-\w\+\.]{,200})(@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3})/) do |matched|
if $1.length < 6
'[FILTERED]' + $2
else
$1[0,3] + '[FILTERED]' + $2
end
end
end
end
module FilterPhone
def filter_phone
if preserve_phone_country_code
preserve_country_code
else
@text.gsub(/(?<![\+A-Za-z0-9])(0(?=[1-9])|(00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/, '[PHONE]')
end
end
def preserve_country_code
@text = @text.gsub(/(?<![\+A-Za-z0-9])((00|\+)[1-9]\d{0,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}/,
'\\1' + " [FILTERED]")
@text.gsub(/(?<![\+A-Za-z0-9])0(?=[1-9])([- \)\(])*\d(\g<1>{,2}\d){5,10}/, '[PHONE]')
end
end
class PrivacyFilter
include FilterEmail, FilterPhone
attr_accessor :preserve_phone_country_code,
:preserve_email_hostname,
:partially_preserve_email_username
def initialize(text)
@text = text
end
def filtered
@text = filter_email
@text = filter_phone
-
- @text
end
end
class Validations
class << self
def email?(value)
/\A[a-zA-Z0-9][-\w\+\.]{,200}@([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def phone?(value)
/\A(0(?=[1-9])|(00|\+)[1-9]\d{,2})([- \)\(])*\d(\g<3>{,2}\d){5,10}\z/.match(value) != nil
end
def hostname?(value)
/\A([a-zA-Z0-9][-a-zA-Z0-9]{,62}(?<!-)\.)+[a-zA-z]{2,3}\z/.match(value) != nil
end
def ip_address?(value)
/\A(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]).\g<1>.\g<1>.\g<1>\z/.match(value) != nil
end
def number?(value)
/\A-?(0|[1-9]\d*|0\.\d+|[1-9]\d*\.\d*)\z/.match(value) != nil
end
def integer?(value)
/\A-?(0|[1-9]\d*)\z/.match(value) != nil
end
def date?(value)
/\A\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])\z/.match(value) != nil
end
def time?(value)
/\A([01]\d|2[0-3]):([0-5]\d):\g<2>\z/.match(value) != nil
end
def date_time?(value)
value_parts = value.split(/ |T/)
date, time = value_parts
value_parts.length == 2 and date?(date) and time?(time) and
value[-1] !~ / |T/
end
end
end