class Holidays::Definition::Validator::Test

Public Instance Methods

valid?(t) click to toggle source
# File lib/holidays/definition/validator/test.rb, line 5
def valid?(t)
  valid_dates?(t[:dates]) &&
    valid_regions?(t[:regions]) &&
    valid_name?(t[:name]) &&
    valid_holiday?(t[:holiday]) &&
    valid_options?(t[:options]) &&
    required_fields?(t)
end

Private Instance Methods

required_fields?(t) click to toggle source
# File lib/holidays/definition/validator/test.rb, line 64
def required_fields?(t)
  return false if t[:name].nil? && t[:holiday].nil?
  true
end
valid_dates?(dates) click to toggle source
# File lib/holidays/definition/validator/test.rb, line 16
def valid_dates?(dates)
  return false unless dates

  dates.all? do |d|
    begin
      DateTime.parse(d)
      true
    rescue TypeError, ArgumentError
      false
    end
  end
end
valid_holiday?(h) click to toggle source

Can be missing

# File lib/holidays/definition/validator/test.rb, line 44
def valid_holiday?(h)
  return true unless h
  h.is_a?(TrueClass)
end
valid_name?(n) click to toggle source

Can be missing

# File lib/holidays/definition/validator/test.rb, line 38
def valid_name?(n)
  return true unless n
  n.is_a?(String)
end
valid_options?(options) click to toggle source

Okay to be missing and can be either string or array of strings

# File lib/holidays/definition/validator/test.rb, line 50
def valid_options?(options)
  return true unless options

  if options.is_a?(Array)
    options.all? do |o|
      o.is_a?(String)
    end
  elsif options.is_a?(String)
    true
  else
    false
  end
end
valid_regions?(regions) click to toggle source
# File lib/holidays/definition/validator/test.rb, line 29
def valid_regions?(regions)
  return false unless regions

  regions.all? do |r|
    r.is_a?(String)
  end
end