Class: Uniword::Resource::DocumentElementTemplate
- Inherits:
-
Object
- Object
- Uniword::Resource::DocumentElementTemplate
- 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
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
Class Method Summary collapse
-
.from_hash(data) ⇒ DocumentElementTemplate
Load from parsed YAML hash.
Instance Method Summary collapse
-
#element_names ⇒ Array<String>
List element names.
-
#find_element(name) ⇒ Hash?
Find element by name.
-
#initialize(locale:, category:, description: "", elements: []) ⇒ DocumentElementTemplate
constructor
Create a new template collection.
Constructor Details
#initialize(locale:, category:, description: "", elements: []) ⇒ DocumentElementTemplate
Create a new template collection
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
#category ⇒ Object (readonly)
Returns the value of attribute category.
10 11 12 |
# File 'lib/uniword/resource/document_element_template.rb', line 10 def category @category end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
10 11 12 |
# File 'lib/uniword/resource/document_element_template.rb', line 10 def description @description end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
10 11 12 |
# File 'lib/uniword/resource/document_element_template.rb', line 10 def elements @elements end |
#locale ⇒ Object (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
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_names ⇒ Array<String>
List 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
42 43 44 |
# File 'lib/uniword/resource/document_element_template.rb', line 42 def find_element(name) elements.find { |e| e["name"] == name } end |