Module: Narou
- Defined in:
- lib/narou.rb
Constant Summary collapse
- LOCAL_SETTING_DIR =
".narou"
- GLOBAL_SETTING_DIR =
".narousetting"
- AOZORAEPUB3_JAR_NAME =
"AozoraEpub3.jar"
- AOZORAEPUB3_DIR =
"./AozoraEpub3"
- PRESET_DIR =
"./preset"
- @@root_dir =
nil
- @@local_setting_dir =
nil
- @@global_setting_dir =
nil
- @@aozora_jar_path =
nil
- @@preset_dir =
nil
Class Method Summary collapse
- .alias_to_id(target) ⇒ Object
- .already_init? ⇒ Boolean
- .aozoraepub3_directory?(path) ⇒ Boolean
- .create_aozoraepub3_jar_path(*paths) ⇒ Object
- .create_novel_filename(novel_data, ext = "") ⇒ Object
-
.get_aozoraepub3_path ⇒ Object
AozoraEpub3 の実行ファイル(.jar)のフルパス取得 検索順序 1.
- .get_ebook_file_path(target, ext) ⇒ Object
- .get_global_setting_dir ⇒ Object
- .get_local_setting_dir ⇒ Object
- .get_mobi_path(target) ⇒ Object
- .get_preset_dir ⇒ Object
- .get_root_dir ⇒ Object
- .get_script_dir ⇒ Object
- .init ⇒ Object
- .novel_frozen?(target) ⇒ Boolean
Class Method Details
.alias_to_id(target) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/narou.rb', line 77 def self.alias_to_id(target) aliases = LocalSetting.get["alias"] if aliases[target] return aliases[target] end target end |
.already_init? ⇒ Boolean
64 65 66 |
# File 'lib/narou.rb', line 64 def self.already_init? !!get_root_dir end |
.aozoraepub3_directory?(path) ⇒ Boolean
100 101 102 |
# File 'lib/narou.rb', line 100 def self.aozoraepub3_directory?(path) File.exists?(create_aozoraepub3_jar_path(path)) end |
.create_aozoraepub3_jar_path(*paths) ⇒ Object
96 97 98 |
# File 'lib/narou.rb', line 96 def self.create_aozoraepub3_jar_path(*paths) File.(File.join(*paths, AOZORAEPUB3_JAR_NAME)) end |
.create_novel_filename(novel_data, ext = "") ⇒ Object
131 132 133 134 |
# File 'lib/narou.rb', line 131 def self.create_novel_filename(novel_data, ext = "") info = Hash[novel_data.map { |k, v| [k, v.sub(/^[ ]*(.+?)[ ]*$/, "\\1")] }] "[#{info["author"]}] #{info["title"]}#{ext}" end |
.get_aozoraepub3_path ⇒ Object
AozoraEpub3 の実行ファイル(.jar)のフルパス取得 検索順序
-
グローバルセッティング (global_setting aozoraepub3dir)
-
小説保存ディレクトリ(Narou.get_root_dir) 直下の AozoraEpub3
-
スクリプト保存ディレクトリ(Narou.get_script_dir) 直下の AozoraEpub3
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/narou.rb', line 111 def self.get_aozoraepub3_path return @@aozora_jar_path if @@aozora_jar_path global_setting_aozora_path = GlobalSetting.get["global_setting"]["aozoraepub3dir"] if global_setting_aozora_path aozora_jar_path = create_aozoraepub3_jar_path(global_setting_aozora_path) if File.exists?(aozora_jar_path) @@aozora_jar_path = aozora_jar_path return aozora_jar_path end end [Narou.get_root_dir, Narou.get_script_dir].each do |dir| aozora_jar_path = create_aozoraepub3_jar_path(dir, AOZORAEPUB3_DIR) if File.exists?(aozora_jar_path) @@aozora_jar_path = aozora_jar_path return aozora_jar_path end end nil end |
.get_ebook_file_path(target, ext) ⇒ Object
140 141 142 143 144 145 |
# File 'lib/narou.rb', line 140 def self.get_ebook_file_path(target, ext) data = Downloader.get_data_by_target(target) return nil unless data dir = Downloader.get_novel_data_dir_by_target(target) File.join(dir, create_novel_filename(data, ext)) end |
.get_global_setting_dir ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/narou.rb', line 51 def self.get_global_setting_dir return @@global_setting_dir if @@global_setting_dir @@global_setting_dir = File.(File.join("~", GLOBAL_SETTING_DIR)) unless File.exists?(@@global_setting_dir) FileUtils.mkdir(@@global_setting_dir) end @@global_setting_dir end |
.get_local_setting_dir ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/narou.rb', line 42 def self.get_local_setting_dir return @@local_setting_dir if @@local_setting_dir root_dir = get_root_dir if root_dir @@local_setting_dir = File.join(root_dir, LOCAL_SETTING_DIR) end @@local_setting_dir end |
.get_mobi_path(target) ⇒ Object
136 137 138 |
# File 'lib/narou.rb', line 136 def self.get_mobi_path(target) get_ebook_file_path(target, ".mobi") end |
.get_preset_dir ⇒ Object
90 91 92 93 94 |
# File 'lib/narou.rb', line 90 def self.get_preset_dir return @@preset_dir if @@preset_dir @@preset_dir = File.(File.join(get_script_dir, PRESET_DIR)) @@preset_dir end |
.get_root_dir ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/narou.rb', line 24 def self.get_root_dir return @@root_dir if @@root_dir path = File.(File.dirname(".")) drive_letter = "" if Helper.os_windows? path.gsub!(/^[a-z]:/i, "") drive_letter = $& end while path != "" if File.directory?("#{path}/#{LOCAL_SETTING_DIR}") @@root_dir = drive_letter + path break end path.gsub!(%r!/[^/]*$!, "") end @@root_dir end |
.get_script_dir ⇒ Object
60 61 62 |
# File 'lib/narou.rb', line 60 def self.get_script_dir @@script_dir ||= File.(File.join(File.dirname(__FILE__), "..")) end |
.init ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/narou.rb', line 68 def self.init return nil if already_init? FileUtils.mkdir(LOCAL_SETTING_DIR) puts LOCAL_SETTING_DIR + "/ を作成しました" Database.init #LocalSetting.get["local_setting"]["device"] = "kindle" #LocalSetting.get.save_settings end |
.novel_frozen?(target) ⇒ Boolean
85 86 87 88 |
# File 'lib/narou.rb', line 85 def self.novel_frozen?(target) id = Downloader.get_id_by_target(target) or return false LocalSetting.get["freeze"].include?(id) end |