Module: CustomFielder::TypeCheckingHelper

Included in:
Field, Value
Defined in:
app/helpers/custom_fielder/type_checking_helper.rb

Constant Summary collapse

TRUTH_VALUES =
[true,  1, '1', 't', 'T', 'true',  'TRUE',  'on',  'ON']
FALSE_VALUES =
[false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF']

Instance Method Summary collapse

Instance Method Details

#is_array?(value) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/helpers/custom_fielder/type_checking_helper.rb', line 22

def is_array?(value)
  value =~ /^\[(.(, )?)+\]$/
end

#is_boolean?(value) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/helpers/custom_fielder/type_checking_helper.rb', line 60

def is_boolean?(value)
  TRUTH_VALUES.include?(value) or FALSE_VALUES.include?(value)
end

#is_correct_type?(type, value) ⇒ Boolean

Runs the the type checking function for the passed type

Parameters:

  • type (String)

    the type to be checked

  • value (String)

    the value to be type checked

Returns:

  • (Boolean)


15
16
17
# File 'app/helpers/custom_fielder/type_checking_helper.rb', line 15

def is_correct_type?(type, value)
  send("is_#{type.underscore}?", value)
end

#is_date?(value) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/helpers/custom_fielder/type_checking_helper.rb', line 43

def is_date?(value)
  value =~ /^\d{4}-\d{2}-\d{2}$/
end

#is_date_time?(value) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
# File 'app/helpers/custom_fielder/type_checking_helper.rb', line 50

def is_date_time?(value)
  value =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/ or
  value =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/ or
  value =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}$/ or
  value =~ /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:\d{2}$/
end

#is_fixnum?(value) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/helpers/custom_fielder/type_checking_helper.rb', line 29

def is_fixnum?(value)
  value =~ /^\d+$/
end

#is_float?(value) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/helpers/custom_fielder/type_checking_helper.rb', line 36

def is_float?(value)
  value =~ /^\d+\.\d+$/
end

#is_string?(value) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/helpers/custom_fielder/type_checking_helper.rb', line 67

def is_string?(value)
  true
end