Method: Hitimes::Stats#to_json

Defined in:
lib/hitimes/stats.rb

#to_json(*args) ⇒ Object

call-seq:

stat.to_json  -> String
stat.to_json( *args ) -> String

return a json string of the stats. By default this returns a json string of all the stats. If an array of items is passed in, those that match the known stats will be all that is included in the json output.



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/hitimes/stats.rb', line 141

def to_json(*args)
  stats = to_hash(*args)
  slugs = []
  out = StringIO.new

  out.print "{ "
  stats.each_pair do |key, val|
    slugs << "\"#{key}\": #{val}"
  end
  out.print slugs.join(", ")
  out.print "}"
  out.string
end