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