Mary Rose Cook

Kisses: the codename for my new app, and fun little functions

Get the indefinite article for a noun:

VOWELS = ["a", "e", "i", "o", "u"]
def self.indefinite_article(str)
article = ""
VOWELS.include?(str.to_s[0..0].downcase) && !str.to_s[1..1].match(/[A-Z]/) ? article = "An" : article = "A" if str
return article
end
view raw gistfile1.rb hosted with ❤ by GitHub


Convert a number like 28,947,345 to a vaguer, but more digestible, statement like 29 million:

VAGARIES = {4 => "thousand", 7 => "million", 10 => "billion", 13 => "trillion"}
def self.vagarise(num)
num = num.to_s
vaguest = num
for vagary in VAGARIES.keys().sort { |x,y| x <=> y }
if num.length >= vagary
unit = num[0..2].to_f / (10 ** (2 - (num.length - vagary)))
vaguest = unit.round().to_s + " " + VAGARIES[vagary]
end
end
return vaguest
end
view raw gistfile1.rb hosted with ❤ by GitHub

Subscribe to my newsletter to hear about my latest work