aboutsummaryrefslogtreecommitdiff
path: root/src/guff/post.cr
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-03-08 00:30:41 -0500
committerPaul Duncan <pabs@pablotron.org>2016-03-08 00:30:41 -0500
commit172304157f582a99fd2bba32fad7ed1018bf0b49 (patch)
treef55c23ee7c08cef2bb33465ed63f3c262c2fa1ce /src/guff/post.cr
parent2d6635b4ff0393af6d97b93772bc566c331de08e (diff)
downloadold-guff-172304157f582a99fd2bba32fad7ed1018bf0b49.tar.bz2
old-guff-172304157f582a99fd2bba32fad7ed1018bf0b49.zip
post json fixes
Diffstat (limited to 'src/guff/post.cr')
-rw-r--r--src/guff/post.cr21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/guff/post.cr b/src/guff/post.cr
index 7247e15..735682c 100644
--- a/src/guff/post.cr
+++ b/src/guff/post.cr
@@ -1,10 +1,21 @@
-class Guff:Post
+class Guff::Post
def initialize(@row : Hash(String, ::SQLite3::Value))
end
- def to_json
- @row.merge({
- "tags": @row["tags"].split('|')
- }).to_json
+ def to_json(io)
+ @row.reduce({} of String => String | Array(String)) do |r, k, v|
+ r[k] = v.to_s
+ r
+ end.merge({
+ "tags": tags
+ }).to_json(io)
+ end
+
+ private def tags : Array(String)
+ @tags ||= if @row.has_key?("tags") && (@row["tags"] as String).size > 0
+ (@row["tags"] as String).split('|')
+ else
+ [] of String
+ end
end
end