Skip to content

Instantly share code, notes, and snippets.

@jwaldrip
Last active August 30, 2017 20:37
Show Gist options
  • Save jwaldrip/e118818abd5ee0fe59ea9da74eaad9ec to your computer and use it in GitHub Desktop.
Save jwaldrip/e118818abd5ee0fe59ea9da74eaad9ec to your computer and use it in GitHub Desktop.
def self.reserved_value?(value, checks = 0)
return true if YAML::RESERVED_VALUES.includes?(value)
just_value = value.ljust(5, 'x')
case {just_value[0], just_value[1], just_value[2], just_value[3], just_value[4]}
when {.ascii_number?, .ascii_number?, .ascii_number?, .ascii_number?, '-'}
(Time::Format::ISO_8601_DATE_TIME.parse(value) rescue false)
when {.ascii_number?, _, _, _, _},
{'-', .ascii_number?, _, _, _},
{'+', .ascii_number?, _, _, _},
{'.', .ascii_number?, _, _, _},
{'-', '.', .ascii_number?, _, _},
{'+', '.', .ascii_number?, _, _}
clean_value = value.gsub('_', "")
clean_value.to_f64? || clean_value.to_i64?(prefix: true)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment