Class: ModpackLocalizer::SNBT::Formatter

Inherits:
Object
  • Object
show all
Includes:
IndentHelper
Defined in:
lib/modpack_localizer/snbt/formatter.rb

Overview

翻訳された内容をSNBT形式に整形するクラス

Instance Method Summary collapse

Methods included from IndentHelper

#count_indent, #create_indent, #middle_indent

Instance Method Details

#adjust_line_length(content) ⇒ void

This method returns an undefined value.

行数をstart_line~end_lineと一致させる

Parameters:

  • content (Hash)

    コンテンツ



35
36
37
38
39
40
41
42
43
# File 'lib/modpack_localizer/snbt/formatter.rb', line 35

def adjust_line_length(content)
  required_lines = extract_required_line_counts(content)
  lines = content[:text].split("\n")

  delete_over_lines(lines, required_lines)
  add_missing_lines(lines, required_lines, content[:indent])

  lines
end

#format_for_snbt(lines, indent, content) ⇒ String

SNBT形式に整形

Parameters:

  • lines (Array<String>)

  • indent (String)

    インデント

  • content (Hash)

    コンテンツ

Returns:

  • (String)

    SNBT形式に整形した行



25
26
27
28
29
# File 'lib/modpack_localizer/snbt/formatter.rb', line 25

def format_for_snbt(lines, indent, content)
  lines = prepare_lines_for_snbt(lines, content)
  formatted_lines = format_lines(lines, indent, content)
  "#{indent}#{content[:type]}: #{formatted_lines}"
end

#format_overwritable_lines(content, indent) ⇒ String

保存できるように整形

Parameters:

  • content (Hash)

    コンテンツ

  • indent (String)

    インデント

Returns:

  • (String)

    SNBT形式に整形したコンテンツ



14
15
16
17
# File 'lib/modpack_localizer/snbt/formatter.rb', line 14

def format_overwritable_lines(content, indent)
  full_lines = adjust_line_length(content)
  format_for_snbt(full_lines, indent, content)
end