Class: Vivlio::Starter::CLI::TokenResolver::Resolver
- Inherits:
-
Object
- Object
- Vivlio::Starter::CLI::TokenResolver::Resolver
- Defined in:
- lib/vivlio/starter/cli/token_resolver.rb
Overview
入力の正規化、カタログの読み込み、両者の照合を一括管理する。CLIコマンド側は Resolver を呼ぶだけで、複雑なトークン解析から解放される。
Constant Summary collapse
- AUTO_NUMBER_MAX =
98- KIND_RANGES =
章番号の範囲から kind を決定するためのマッピング。00: preface, 01-89: chapter, 90-98: appendix, 99: postface
{ preface: 0..0, chapter: 1..89, appendix: 90..98, postface: 99..99 }.freeze
- SYSTEM_FILE_KINDS =
システム予約ファイルの kind マッピング。カタログに載らない特殊ファイルを仮想 Entry として解決するために使用。
{ '_titlepage' => :titlepage, '_legalpage' => :legalpage, '_colophon' => :colophon, '_indexpage' => :indexpage, '_glossarypage' => :glossarypage, '_toc' => :toc }.freeze
- CACHED_SYSTEM_FILES =
.cache/vs/ に生成されるシステムページ(contents/ ではなくキャッシュに配置)
%w[_titlepage _legalpage _colophon].freeze
Instance Method Summary collapse
-
#initialize(catalog_path: 'config/catalog.yml', contents_dir: 'contents') ⇒ Resolver
constructor
A new instance of Resolver.
-
#resolve(tokens = []) ⇒ Array<Entry>
メイン入口:引数があればそれを解決し、無ければカタログ全件を返す。.
-
#resolve_file(file_path) ⇒ Entry
ファイルパスから Entry を取得する便利メソッド。.
Constructor Details
#initialize(catalog_path: 'config/catalog.yml', contents_dir: 'contents') ⇒ Resolver
Returns a new instance of Resolver.
63 64 65 66 |
# File 'lib/vivlio/starter/cli/token_resolver.rb', line 63 def initialize(catalog_path: 'config/catalog.yml', contents_dir: 'contents') @catalog_path = catalog_path @contents_dir = contents_dir end |
Instance Method Details
#resolve(tokens = []) ⇒ Array<Entry>
メイン入口:引数があればそれを解決し、無ければカタログ全件を返す。
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vivlio/starter/cli/token_resolver.rb', line 71 def resolve(tokens = []) catalog = load_catalog_entries reset_number_tracking(catalog) if tokens.empty? # 引数なし:catalog.yml にある全章を対象とする (build 等) catalog else # 引数あり:入力を正規化してカタログと突き合わせる normalize(tokens).map { match_entry(it, catalog) } end end |
#resolve_file(file_path) ⇒ Entry
ファイルパスから Entry を取得する便利メソッド。
87 88 89 90 |
# File 'lib/vivlio/starter/cli/token_resolver.rb', line 87 def resolve_file(file_path) basename = File.basename(file_path).sub(/\.(md|html)\z/i, '') resolve([basename]).first end |