module Suretax::Concerns::Validatable::Validations

Public Instance Methods

optional_north_american_phone_number?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 159
def optional_north_american_phone_number?(value)
  blank?(value) || north_american_phone_number?(value)
end
valid_bill_to_number?(value)
valid_business_unit?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 99
def valid_business_unit?(value)
  blank?(value) || (value.length <= 20 && alphanumeric?(value))
end
valid_client_number?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 93
def valid_client_number?(value)
  return false if blank?(value)
  numeric?(value) && value.length <= 10
end
Also aliased as: valid_customer_number?
valid_client_tracking?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 117
def valid_client_tracking?(value)
  blank?(value) || value.length <= 100
end
valid_customer_number?(value)
valid_data_month?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 81
def valid_data_month?(value)
  matches?(value, month_list_subexpression)
end
valid_data_year?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 75
def valid_data_year?(value)
  return false if blank?(value)
  value.length == 4 &&
    (value.to_i <= 2050 && value.to_i >= 1990)
end
valid_invoice_number?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 133
def valid_invoice_number?(value)
  blank?(value) || (value.length <= 20 && alphanumeric?(value))
end
valid_items?(items) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 85
def valid_items?(items)
  items.none? { |item| item.errors.any? }
end
valid_line_number?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 129
def valid_line_number?(value)
  blank?(value) || (value.length <= 20 && alphanumeric?(value))
end
valid_list?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 89
def valid_list?(value)
  value.respond_to?(:each)
end
valid_orig_number?(value)
valid_regulatory_code?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 150
def valid_regulatory_code?(value)
  !blank?(value) && Suretax::REGULATORY_CODES.values.include?(value)
end
valid_response_group?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 121
def valid_response_group?(value)
  Suretax::RESPONSE_GROUPS.values.include?(value)
end
valid_response_type?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 125
def valid_response_type?(value)
  /\A[DSA][1-9]?\Z/ === value
end
valid_return_file_code?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 113
def valid_return_file_code?(value)
  matches?(value.to_s, "[Q0]")
end
valid_sales_type_code?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 145
def valid_sales_type_code?(value)
  match_value = "[#{Suretax::SALES_TYPE_CODES.values.join}]"
  !blank?(value) && matches?(value, match_value)
end
valid_tax_exemption_code_list?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 154
def valid_tax_exemption_code_list?(value)
  valid_list?(value) && !blank?(value.first)
end
Also aliased as: valid_tax_exemption_codes?
valid_tax_exemption_codes?(value)
valid_tax_situs_rule?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 137
def valid_tax_situs_rule?(value)
  Suretax::TAX_SITUS_RULES.values.include?(value)
end
valid_term_number?(value)
valid_total_revenue?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 108
def valid_total_revenue?(value)
  matches?(value, total_revenue_positive_subexpression) ||
    matches?(value, total_revenue_negative_subexpression)
end
valid_trans_type_code?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 141
def valid_trans_type_code?(value)
  !blank?(value)
end
valid_validation_key?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 103
def valid_validation_key?(value)
  return false if blank?(value)
  value.length <= 36
end

Private Instance Methods

alphanumeric?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 184
def alphanumeric?(value)
  matches?(value, "[a-z0-9]+")
end
blank?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 188
def blank?(value)
  value.nil? || matches?(value, '\s*')
end
matches?(value, subexpression) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 192
def matches?(value, subexpression)
  /\A#{subexpression}\z/i === value
end
month_list_subexpression() click to toggle source

Month numbers 1-12 with optional leading zero

# File lib/suretax/concerns/validatable.rb, line 197
def month_list_subexpression
  "0?(?:" + (1..12).to_a.join("|") + ")"
end
north_american_phone_number?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 168
def north_american_phone_number?(value)
  !blank?(value) && (value.length == 10 && numeric?(value))
end
numeric?(value) click to toggle source
# File lib/suretax/concerns/validatable.rb, line 180
def numeric?(value)
  matches?(value, '\d+')
end
total_revenue_negative_subexpression() click to toggle source
# File lib/suretax/concerns/validatable.rb, line 172
def total_revenue_negative_subexpression
  '-\d{,8}(?:\.\d{,4})?'
end
total_revenue_positive_subexpression() click to toggle source
# File lib/suretax/concerns/validatable.rb, line 176
def total_revenue_positive_subexpression
  '\d{,9}(?:\.\d{,4})?'
end