You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.0 KiB

  1. #!/usr/bin/env ruby
  2. auth_keys = ['apiKey', 'OAuth', 'X-Mashape-Key', 'No']
  3. punctuation = ['.', '?', '!']
  4. https_keys = ['Yes', 'No']
  5. args = ARGV
  6. filename = args[0]
  7. fail_flag = false
  8. File.foreach(filename).with_index do |line, line_num|
  9. line_num += 1
  10. if line.start_with?('|')
  11. # Skip table schema lines
  12. if line.eql? "|---|---|---|---|---|\n"
  13. next
  14. end
  15. values = line.split("|")
  16. ################# DESCRIPTION ################
  17. # First character should be capitalized
  18. desc_val = values[2].lstrip.chop
  19. if !/[[:upper:]]/.match(desc_val[0])
  20. puts "(#{line_num}) Invalid Description (first char not uppercase): #{desc_val}"
  21. fail_flag = true
  22. end
  23. # value should not be punctuated
  24. last_char = desc_val[desc_val.length-1]
  25. if punctuation.include?(last_char)
  26. puts "(#{line_num}) Invalid Description (description should not end with \"#{last_char}\")"
  27. fail_flag = true
  28. end
  29. #################### AUTH ####################
  30. # Values should conform to valid options only
  31. auth_val = values[3].lstrip.chop.tr('``', '')
  32. if !auth_keys.include?(auth_val)
  33. puts "(#{line_num}) Invalid Auth (not a valid option): #{auth_val}"
  34. fail_flag = true
  35. end
  36. #################### HTTPS ###################
  37. # Values should be either "Yes" or "No"
  38. https_val = values[4].lstrip.chop
  39. if !https_keys.include?(https_val)
  40. puts "(#{line_num}) Invalid HTTPS: (must use \"Yes\" or \"No\"): #{https_val}"
  41. fail_flag = true
  42. end
  43. #################### LINK ####################
  44. # Url should be wrapped in "[Go!]" view
  45. link_val = values[5].lstrip.chop
  46. if !link_val.start_with?("[Go!](") || !link_val.end_with?(')')
  47. puts "(#{line_num}) Invalid Link: (format should be \"[Go!](<LINK>)\"): #{link_val}"
  48. fail_flag = true
  49. end
  50. end
  51. end
  52. if fail_flag
  53. exit(1)
  54. else
  55. exit(0)
  56. end