Skip to content

Class HTM::Models::Tag

Inherits Object
Defined in lib/htm/models/tag.rb

Tag model - represents unique tag names Tags have a many-to-many relationship with nodes through node_tags

Constants

TAG_FORMAT

Tag name format regex

Public Class Methods

calculate_node_positions(node, depth, positions, y_offset, h_spacing, v_spacing, parent_path = nil)

Calculate node positions for SVG layout (internal helper)

calculate_tree_stats(node, depth = 0)

Calculate tree statistics (internal helper)

empty_tree_svg(title)

Generate SVG for empty tree (internal helper)

exists?(conditions = {})

Check if a tag exists with the given conditions - @param conditions [Hash] Conditions to check - @return [Boolean] true if a matching tag exists

expand_hierarchy(tag_name)

Expand a hierarchical tag name into all ancestor paths - @param tag_name [String] Hierarchical tag (e.g., "a🅱c:d") - @return [Array] All paths from root to leaf

find_by_topic_prefix(prefix)

Find tags with a given prefix (hierarchical query) - @param prefix [String] Tag prefix to match (e.g., "database" matches "database:postgresql") - @return [Sequel::Dataset] Tags matching the prefix

find_or_create_by_name(name)

Find or create a tag by name - @param name [String] Hierarchical tag name (e.g., "database:postgresql") - @return [Tag] The found or created tag

find_or_create_with_ancestors(name)

Find or create a tag and all its ancestor tags - @param name [String] Hierarchical tag name (e.g., "database:postgresql:extensions") - @return [Array] All created/found tags from root to leaf

format_tree_branch(node, is_last_array = [])

Format a tree branch recursively (internal helper)

generate_mermaid_nodes(node, parent_path, lines, node_ids, counter)

Generate Mermaid nodes recursively (internal helper)

generate_tree_svg(tree_data, positions, width, height, padding, node_width, node_height, title)

Generate SVG tree visualization (internal helper)

Get the most frequently used tags - @param limit [Integer] Maximum number of tags to return (default: 10) - @return [Array] Tags with usage_count attribute

svg_edge_path(x1, y1, x2, y2)

Not documented.

svg_node_coords(pos, parent_pos, padding, node_width, node_height)

Not documented.

svg_node_elements(path, pos, parent_pos, colors, padding, node_width, node_height)

Not documented.

svg_node_label(x, y, node_width, node_height, label)

Not documented.

svg_node_rect(x, y, node_width, node_height, color)

Not documented.

svg_title_element(width, title)

Not documented.

tree()

Returns a nested hash tree structure from the current scope - @return [Hash] Nested hash representing the tag hierarchy

tree_mermaid(direction: 'TD')

Returns a Mermaid flowchart representation of the tag tree - @param direction [String] Flow direction: 'TD' (top-down), 'LR' (left-right), 'BT', 'RL' - @return [String] Mermaid flowchart syntax

tree_string()

Returns a formatted string representation of the tag tree - @return [String] Formatted tree string

tree_svg(title: 'HTM Tag Hierarchy')

Returns an SVG representation of the tag tree - @param title [String] Optional title for the SVG - @return [String] SVG markup

Public Instance Methods

before_create()

Hooks

deleted?()

Check if tag is soft-deleted - @return [Boolean] true if deleted_at is set

depth()

Get the depth (number of levels) of this tag - @return [Integer] Number of hierarchy levels

hierarchical?()

Check if this tag is hierarchical (has child levels) - @return [Boolean] True if tag contains colons (hierarchy separators)

restore!()

Restore a soft-deleted tag - @return [Boolean] true if restored successfully

root_topic()

Get the root (top-level) topic of this tag - @return [String] The first segment of the hierarchical tag

soft_delete!()

Soft delete - mark tag as deleted without removing from database - @return [Boolean] true if soft deleted successfully

topic_levels()

Get all hierarchy levels of this tag - @return [Array] Array of topic segments

usage_count()

Get the number of nodes using this tag - @return [Integer] Count of nodes with this tag

validate()

Validations