Skip to content

Instantly share code, notes, and snippets.

@johnschult
Created January 29, 2009 17:51
Show Gist options
  • Save johnschult/54646 to your computer and use it in GitHub Desktop.
Save johnschult/54646 to your computer and use it in GitHub Desktop.
def extended_encode(data_arr, max_value)
# Douglas F Shearer 2007
# http://douglasfshearer.com/blog/ruby-google-charts-api-data-encoding
characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.'.split(//)
data = ''
data_arr.each do |value|
if value.is_a?(Integer) && value >= 0
new_value = ((4095 * value.to_f / max_value.to_f).to_i)
sixtyfours = new_value/64
units = new_value%64
p '64:' + sixtyfours.to_s
p 'units: ' + units.to_s
data << characters[sixtyfours] + characters[units]
else
data << '__'
end
end
data
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment