Class: Ace::Compressor::Atoms::CanonicalBlockTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/compressor/atoms/canonical_block_transformer.rb

Constant Summary collapse

RULE_RE =
/\b(?:must|must not|never|required|required to|should|shall|shall not|cannot|can't|do not)\b/i
CONSTRAINT_RE =
/\b(?:constraint|no more than|at most|must not|never|cannot)\b/i
RULE_SECTION_RE =
/(rules?|guidelines?|policy|requirements?|constraints?|musts?)/i
SUMMARY_SECTION_RE =
/(overview|summary|vision|purpose|goal|why|motivation|introduction|intro)/i
EXAMPLE_HEADING_RE =
/\Aexample\s*:\s*(.+)\z/i
PROBLEM_SECTION_RE =
/(problems?|issues?|risks?|pitfalls?|drawbacks?)/i
PROBLEM_CONTEXT_RE =
/\b(?:suffer from|struggle with|problems?|issues?|risks?|pitfalls?|drawbacks?|pain points?)\b/i
TREE_LINE_RE =
/[│├└╰]--/
FILE_PATH_RE =
/\A(?:\.{1,2}\/)?[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)*\z/
SHELL_LANGS =
%w[bash sh shell zsh fish cmd powershell ps1].freeze
SHELL_CONTROL_RE =
/\A(?:#|if\b|then\b|else\b|elif\b|fi\b|for\b|while\b|until\b|do\b|done\b|case\b|esac\b|function\b|\{|\})/
CONTEXTPACK_PREFIXES =
%w[
  H FILE POLICY FIDELITY REFUSAL GUIDANCE FALLBACK SEC SUMMARY FACT RULE CONSTRAINT
  PROBLEMS LIST EXAMPLE CMD FILES TREE CODE TABLE LOSS EXAMPLE_REF U
].freeze
LIST_NARRATIVE_MIN_CHARS =
48
LIST_NARRATIVE_MIN_WORDS =
6
LIST_STOPWORDS =
%w[a an and as at by for from in into is of on or that the this to via with within].freeze
LIST_TOKEN_MAP =
{
  "architecture" => "arch",
  "architectural" => "arch",
  "configuration" => "config",
  "documentation" => "docs",
  "generation" => "gen",
  "management" => "mgmt",
  "repository" => "repo",
  "repositories" => "repos",
  "development" => "dev",
  "integration" => "integr",
  "execution" => "exec",
  "reporting" => "reports",
  "organization" => "org",
  "organizations" => "orgs",
  "capabilities" => "caps",
  "capability" => "cap",
  "foundation" => "base",
  "tracking" => "track",
  "powered" => "pwr",
  "detected" => "detect",
  "matching" => "match"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ CanonicalBlockTransformer

Returns a new instance of CanonicalBlockTransformer.



49
50
51
52
53
54
# File 'lib/ace/compressor/atoms/canonical_block_transformer.rb', line 49

def initialize(source)
  @source = source
  @current_section = nil
  @example_tool = nil
  @last_text = nil
end

Instance Method Details

#call(blocks) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ace/compressor/atoms/canonical_block_transformer.rb', line 56

def call(blocks)
  lines = []

  Array(blocks).each do |block|
    next unless block.is_a?(Hash) && block[:type]

    case block[:type]
    when :heading
      lines << section_line(block)
    when :text
      lines << text_record(block[:text])
    when :list
      lines.concat list_lines(block)
    when :fenced_code
      lines.concat fenced_code_lines(block)
    when :table
      table = table_line(block)
      lines << table if table
    when :unresolved
      lines << unresolved_line(block)
    end
  end

  lines.compact
end