Module: ModpackLocalizer::SNBT::TitleExtractor

Includes:
IndentHelper
Included in:
Reader
Defined in:
lib/modpack_localizer/snbt/title_extractor.rb

Overview

SNBT形式のファイルからtitle: “some title”を抽出するモジュール

Instance Method Summary collapse

Methods included from IndentHelper

#count_indent, #create_indent, #middle_indent

Instance Method Details

#extract_titles(file_path) ⇒ Array<Hash>

title: “some title”を抽出する

Parameters:

  • file_path (String)

    ファイルのパス

Returns:

  • (Array<Hash>)

    タイトルと行番号の配列



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/modpack_localizer/snbt/title_extractor.rb', line 13

def extract_titles(file_path)
  titles = []
  lines = File.readlines(file_path)
  lines.each_with_index do |line, index|
    next unless start_of?(line, key: :title)

    titles << {
      type: :title,
      text: extract_oneline(line),
      start_line: index,
      end_line: index,
      indent: count_indent(line)
    }
  end

  titles
end