Class: BlockLabel

Inherits:
Object show all
Defined in:
lib/block_label.rb

Overview

This class is used to represent a block label which can be constructed using various components. It handles initialization using a hash and provides a method to create a label string.

Example Usage: block =

filename: 'example.md',
headings: ['Header1', 'Header2'],
menu_blocks_with_docname: true,
menu_blocks_with_headings: false,
title: 'Sample Title',
body: 'Sample Body',
text: 'Sample Text'

label_obj = BlockLabel.new(block) label_str = label_obj.make

Class Method Summary collapse

Class Method Details

.make(filename:, headings:, menu_blocks_with_docname:, menu_blocks_with_headings:, title:, body:, text:) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/block_label.rb', line 25

def self.make(filename:, headings:, menu_blocks_with_docname:, menu_blocks_with_headings:, title:, body:, text:)
  label = title
  label = body if label.nil? || label.empty?
  label = text if label.nil? || label.empty?

  parts = [label]

  parts << headings.compact.join(' # ') if menu_blocks_with_headings
  parts << filename if menu_blocks_with_docname

  parts.join('  ')
rescue StandardError => err
  warn(error = "ERROR ** BlockLabel.make(); #{err.inspect}")
  binding.pry if $tap_enable
  raise ArgumentError, error
end