Add rename method to Manga and Chapter

This commit is contained in:
Alex Ling 2020-05-07 10:12:06 +00:00
parent b7cd55e692
commit 09b297cd8e

View File

@ -14,6 +14,14 @@ macro parse_strings_from_json(names)
{% end %} {% end %}
end end
macro properties_to_hash(names)
{
{% for name in names %}
"{{name.id}}" => @{{name.id}}.to_s,
{% end %}
}
end
module MangaDex module MangaDex
class Chapter class Chapter
string_properties ["lang_code", "title", "volume", "chapter"] string_properties ["lang_code", "title", "volume", "chapter"]
@ -74,6 +82,13 @@ module MangaDex
rescue e rescue e
raise "failed to parse json: #{e}" raise "failed to parse json: #{e}"
end end
def rename(rule : Rename::Rule)
hash = properties_to_hash ["id", "title", "volume", "chapter",
"lang_code", "language", "pages"]
hash["groups"] = @groups.map { |g| g[1] }.join ","
rule.render hash
end
end end
class Manga class Manga
@ -111,6 +126,10 @@ module MangaDex
rescue e rescue e
raise "failed to parse json: #{e}" raise "failed to parse json: #{e}"
end end
def rename(rule : Rename::Rule)
rule.render properties_to_hash ["id", "title", "author", "artist"]
end
end end
class API class API