Skip to content

Instantly share code, notes, and snippets.

@lenagroeger
Created September 11, 2012 21:12
Show Gist options
  • Save lenagroeger/3702094 to your computer and use it in GitHub Desktop.
Save lenagroeger/3702094 to your computer and use it in GitHub Desktop.
fmt_stat for fracking
def fmt_stat(stat, prefix = stat > 0 ? "$" : "")
stat = case stat
when -999999999999..-10000 then number_to_human(stat, :units => {:million => "M", :thousand => "K", :billion => "B"}).gsub(/ /,'')
when -9999..-1 then number_with_delimiter(stat)
when 0 then "<em>No Data.</em>"
when 1..9999 then number_with_delimiter(stat)
when 10000..999999999999 then number_to_human(stat, :units => {:million => "M", :thousand => "K", :billion => "B"}).gsub(/ /,'')
when nil then number_with_delimiter(0)
else stat
end
stat = stat === "N/A" ? stat : "#{prefix}#{stat}"
end
def format(sym)
money = [:staff_budget, :oil_and_gas_department_budget]
integers = Field.bolded - money
per = [:total_wells]
return case
when money.include?(sym) then
fmt_stat(send(sym).to_f)
when integers.include?(sym) then
number_with_delimiter(send(sym))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment