diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-03-06 23:12:06 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-03-06 23:12:06 -0500 |
commit | f0f87c439037715cac407004e2220c678d96757a (patch) | |
tree | 40e9330d709f2b33f6e95fa7b87ec6b3990e3c17 /src/guff/results.cr | |
parent | 70e294e312710eb1e89c9cacd09a830e05d4bbe9 (diff) | |
download | old-guff-f0f87c439037715cac407004e2220c678d96757a.tar.bz2 old-guff-f0f87c439037715cac407004e2220c678d96757a.zip |
chaos!
Diffstat (limited to 'src/guff/results.cr')
-rw-r--r-- | src/guff/results.cr | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/guff/results.cr b/src/guff/results.cr new file mode 100644 index 0000000..0dbc351 --- /dev/null +++ b/src/guff/results.cr @@ -0,0 +1,34 @@ +module Guff + class Results(R) + getter :page + getter :limit + getter :num_rows + getter :rows + + def initialize( + @page = 1 : Int32, + @limit = 1 : Int32, + @num_rows = 0 : Int32, + @rows = [] of R : Array(R), + ) + end + + def to_json + { + meta: { + page: @page, + limit: @limit, + num_pages: (@num_rows / @limit).ceil, + num_rows: @num_rows, + }, + + rows: @rows.map { |row| + row.reduce({} of String => String) do |r, k, v| + r[k] = v.to_s + r + end + }, + }.to_json + end + end +end |