Simplify #json_build

This commit is contained in:
Alex Ling
2021-09-14 02:30:57 +00:00
parent 4b464ed361
commit 4eaf271fa4
4 changed files with 55 additions and 62 deletions
+8 -9
View File
@@ -65,16 +65,15 @@ class Library
titles.flat_map &.deep_entries
end
def build_json(json : JSON::Builder, *, slim = false, shallow = false)
json.object do
json.field "dir", @dir
json.field "titles" do
json.array do
self.titles.each do |title|
raw = JSON.build do |j|
title.build_json j, slim: slim, shallow: shallow
def build_json(*, slim = false, shallow = false)
JSON.build do |json|
json.object do
json.field "dir", @dir
json.field "titles" do
json.array do
self.titles.each do |title|
json.raw title.build_json(slim: slim, shallow: shallow)
end
json.raw raw
end
end
end