Class: Command::Restore346
Instance Attribute Summary
Attributes inherited from CommandBase
#stream_io
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from CommandBase
#disable_logging, #display_help!, execute!, #execute!, #force_change_settings_function, help, #hook_call, #load_local_settings, #tagname_to_ids
Constructor Details
Returns a new instance of Restore346.
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/command/restore346.rb', line 16
def initialize
super("<target> [<target2> ...]")
@opt.separator "\n \u30FBver 3.4.6 \u3067\u66F4\u65B0\u3057\u3066\u58CA\u308C\u305F toc.yaml \u306E\u66F4\u65B0\u65E5\u6642\u90E8\u5206\u3092\u5FA9\u5143\u3057\u307E\u3059\n \u30FB\u3053\u306E\u30B3\u30DE\u30F3\u30C9\u3092\u5B9F\u884C\u3057\u306A\u304F\u3066\u3082\u66F4\u65B0\u306F\u51FA\u6765\u307E\u3059\u304C\u3001\u6539\u7A3F\u304C\u3042\u308B\u8A71\u306EDL\u304C\u8D70\u3063\u3066\u3057\u307E\u3044\u307E\u3059\n\n Examples:\nnarou restore346\n HELP\nend\n"
|
Class Method Details
.oneline_help ⇒ Object
12
13
14
|
# File 'lib/command/restore346.rb', line 12
def self.oneline_help
"ver 3.4.6 で壊れた toc.yaml の復元"
end
|
Instance Method Details
#execute(argv) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/command/restore346.rb', line 28
def execute(argv)
super
database_values = Database.instance.get_object.values
database_values.each do |data|
begin
puts "<gray>#{data["title"].escape}</gray>".termcolor
downloader = Downloader.new(data["id"])
toc = downloader.load_toc_file
modified = restore(toc)
downloader.save_toc_once(toc) if modified
rescue StandardError
next
end
end
end
|
#restore(toc) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/command/restore346.rb', line 44
def restore(toc)
subtitles = toc["subtitles"]
modified = false
subtitles.each do |subtitle|
next unless subtitle["subdate"] =~ /\A(?<subdate>.+?)<span title="(?<subupdate>.+?) 改稿">/
subdate = Regexp.last_match[:subdate]
subupdate = Regexp.last_match[:subupdate]
subtitle["subdate"] = subdate
subtitle["subupdate"] = subupdate
modified = true
end
if modified
puts "<green>#{toc["title"].escape} の目次データを復元しました</green>".termcolor
end
modified
end
|