Module: CustomFielder::TypeCheckingHelper
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
- #is_array?(value) ⇒ Boolean
- #is_boolean?(value) ⇒ Boolean
-
#is_correct_type?(type, value) ⇒ Boolean
Runs the the type checking function for the passed type.
- #is_date?(value) ⇒ Boolean
- #is_date_time?(value) ⇒ Boolean
- #is_fixnum?(value) ⇒ Boolean
- #is_float?(value) ⇒ Boolean
- #is_string?(value) ⇒ Boolean
Instance Method Details
#is_array?(value) ⇒ 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
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
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
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
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
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
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
67 68 69 |
# File 'app/helpers/custom_fielder/type_checking_helper.rb', line 67 def is_string?(value) true end |