Class: Vivlio::Starter::CLI::TocCommands::HeadingExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio/starter/cli/toc.rb

Overview

HTML 見出しから TOC 用項目を生成する

Constant Summary collapse

LEVEL_BY_TAG =
{ 'h1' => 1, 'h2' => 2, 'h3' => 3 }.freeze

Instance Method Summary collapse

Constructor Details

#initialize(target, entry) ⇒ HeadingExtractor

Returns a new instance of HeadingExtractor.

Parameters:

  • target (String)

    HTML ファイルパス

  • entry (TokenResolver::Entry)

    章情報を持つ Entry オブジェクト



334
335
336
337
# File 'lib/vivlio/starter/cli/toc.rb', line 334

def initialize(target, entry)
  @target = target
  @entry = entry
end

Instance Method Details

#headingsObject

ターゲット HTML から見出し情報を配列で返す



340
341
342
# File 'lib/vivlio/starter/cli/toc.rb', line 340

def headings
  nodes.map { |node| build_heading(node) }.compact
end