Add started? and deep_titles helper methods

This commit is contained in:
Alex Ling 2020-06-15 12:05:59 +00:00
parent 3dc9bd2264
commit e28dadc94e

View File

@ -163,6 +163,10 @@ class Entry
def finished?(username)
load_progress(username) == @pages
end
def started?(username)
load_progress(username) > 0
end
end
class Title
@ -257,6 +261,11 @@ class Title
@entries + titles.map { |t| t.deep_entries }.flatten
end
def deep_titles
return [] of Title if titles.empty?
titles + titles.map { |t| t.deep_titles }.flatten
end
def parents
ary = [] of Title
tid = @parent_id
@ -469,6 +478,10 @@ class Library
@title_ids.map { |tid| self.get_title!(tid) }
end
def deep_titles
titles + titles.map { |t| t.deep_titles }.flatten
end
def to_json(json : JSON::Builder)
json.object do
json.field "dir", @dir