Class: LcpRuby::Metadata::DisplayTemplateDefinition
- Inherits:
-
Object
- Object
- LcpRuby::Metadata::DisplayTemplateDefinition
- Defined in:
- lib/lcp_ruby/metadata/display_template_definition.rb
Instance Attribute Summary collapse
-
#badge ⇒ Object
readonly
Returns the value of attribute badge.
-
#icon ⇒ Object
readonly
Returns the value of attribute icon.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#partial ⇒ Object
readonly
Returns the value of attribute partial.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
-
#subtitle ⇒ Object
readonly
Returns the value of attribute subtitle.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Class Method Summary collapse
Instance Method Summary collapse
- #form ⇒ Object
-
#initialize(attrs = {}) ⇒ DisplayTemplateDefinition
constructor
A new instance of DisplayTemplateDefinition.
- #partial? ⇒ Boolean
-
#referenced_fields ⇒ Object
Extract field references from template, subtitle, badge strings.
- #renderer? ⇒ Boolean
-
#string_slots ⇒ Object
The string-valued slots that may carry ‘field` placeholders.
- #structured? ⇒ Boolean
Constructor Details
#initialize(attrs = {}) ⇒ DisplayTemplateDefinition
Returns a new instance of DisplayTemplateDefinition.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 7 def initialize(attrs = {}) @name = attrs[:name].to_s @template = attrs[:template] @subtitle = attrs[:subtitle] @icon = attrs[:icon] @badge = attrs[:badge] @renderer = attrs[:renderer] @partial = attrs[:partial] @options = attrs[:options] || {} validate! end |
Instance Attribute Details
#badge ⇒ Object (readonly)
Returns the value of attribute badge.
4 5 6 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 4 def badge @badge end |
#icon ⇒ Object (readonly)
Returns the value of attribute icon.
4 5 6 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 4 def icon @icon end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 4 def @options end |
#partial ⇒ Object (readonly)
Returns the value of attribute partial.
4 5 6 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 4 def partial @partial end |
#renderer ⇒ Object (readonly)
Returns the value of attribute renderer.
4 5 6 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 4 def renderer @renderer end |
#subtitle ⇒ Object (readonly)
Returns the value of attribute subtitle.
4 5 6 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 4 def subtitle @subtitle end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
4 5 6 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 4 def template @template end |
Class Method Details
.from_hash(name, hash) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 20 def self.from_hash(name, hash) new( name: name, template: hash["template"], subtitle: hash["subtitle"], icon: hash["icon"], badge: hash["badge"], renderer: hash["renderer"], partial: hash["partial"], options: hash["options"] || {} ) end |
Instance Method Details
#form ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 33 def form if @renderer :renderer elsif @partial :partial else :structured end end |
#partial? ⇒ Boolean
51 52 53 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 51 def partial? form == :partial end |
#referenced_fields ⇒ Object
Extract field references from template, subtitle, badge strings. Returns an array of unique field path strings.
63 64 65 66 67 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 63 def referenced_fields @referenced_fields ||= string_slots.values.compact .flat_map { |s| s.scan(/\{([^}]+)\}/).flatten.map(&:strip) } .uniq end |
#renderer? ⇒ Boolean
47 48 49 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 47 def renderer? form == :renderer end |
#string_slots ⇒ Object
The string-valued slots that may carry ‘field` placeholders. Single source of truth for `referenced_fields` and validators.
57 58 59 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 57 def string_slots { "template" => @template, "subtitle" => @subtitle, "badge" => @badge } end |
#structured? ⇒ Boolean
43 44 45 |
# File 'lib/lcp_ruby/metadata/display_template_definition.rb', line 43 def structured? form == :structured end |