Skip to content

Instantly share code, notes, and snippets.

@johnpmitsch
Created June 1, 2015 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnpmitsch/c47d1c045b9929f16c61 to your computer and use it in GitHub Desktop.
Save johnpmitsch/c47d1c045b9929f16c61 to your computer and use it in GitHub Desktop.
find by version
def find_by_version(_key, operator, value)
major, minor = value.split('.')
case
when value.to_f < 1
query = {}
when /[<>]/ =~ operator
minor ||= 0
query = "major #{operator} :major OR (major = :major AND minor #{operator} :minor)"
when minor.nil?
query = "major #{operator} (?)"
else
query = "major #{operator} (?) and minor #{operator} (?)"
end
puts query
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment