Class: Uniword::Resource::DocumentElementTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/resource/document_element_template.rb

Overview

Represents a collection of document element templates for a locale/category.

Document elements are reusable building blocks (cover pages, headers, footers, etc.) defined as human-readable YAML templates.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(locale:, category:, description: "", elements: []) ⇒ DocumentElementTemplate

Create a new template collection

Parameters:

  • locale (String)

    Locale code (e.g., “en”, “ja”, “zh-CN”)

  • category (String)

    Category slug (e.g., “cover_pages”, “headers”)

  • description (String) (defaults to: "")

    Description of this template collection

  • elements (Array<Hash>) (defaults to: [])

    Array of element definitions



18
19
20
21
22
23
# File 'lib/uniword/resource/document_element_template.rb', line 18

def initialize(locale:, category:, description: "", elements: [])
  @locale = locale
  @category = category
  @description = description
  @elements = elements
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



10
11
12
# File 'lib/uniword/resource/document_element_template.rb', line 10

def category
  @category
end

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/uniword/resource/document_element_template.rb', line 10

def description
  @description
end

#elementsObject (readonly)

Returns the value of attribute elements.



10
11
12
# File 'lib/uniword/resource/document_element_template.rb', line 10

def elements
  @elements
end

#localeObject (readonly)

Returns the value of attribute locale.



10
11
12
# File 'lib/uniword/resource/document_element_template.rb', line 10

def locale
  @locale
end

Class Method Details

.from_hash(data) ⇒ DocumentElementTemplate

Load from parsed YAML hash

Parameters:

  • data (Hash)

    Parsed YAML data

Returns:



29
30
31
32
33
34
35
36
# File 'lib/uniword/resource/document_element_template.rb', line 29

def self.from_hash(data)
  new(
    locale: data["locale"],
    category: data["category"],
    description: data["description"] || "",
    elements: data["elements"] || [],
  )
end

Instance Method Details

#element_namesArray<String>

List element names

Returns:

  • (Array<String>)

    Element names



49
50
51
# File 'lib/uniword/resource/document_element_template.rb', line 49

def element_names
  elements.map { |e| e["name"] }
end

#find_element(name) ⇒ Hash?

Find element by name

Parameters:

  • name (String)

    Element name

Returns:

  • (Hash, nil)

    Element definition



42
43
44
# File 'lib/uniword/resource/document_element_template.rb', line 42

def find_element(name)
  elements.find { |e| e["name"] == name }
end