Class: Coradoc::CoreModel::FrontmatterBlock::FrontmatterValue

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/core_model/frontmatter/frontmatter_value.rb

Overview

Single typed value node in a FrontmatterBlock entry tree.

Replaces the previous ‘attribute :data, :hash` representation. Each value carries a `value_type` discriminator plus one populated slot matching that type. Container types (`array`, `map`) hold nested FrontmatterValue / FrontmatterEntry children.

Supported value types (mirror what YAML.safe_load returns given the Codec’s PERMITTED_CLASSES):

scalar  -> string, integer, float, boolean, date, datetime, symbol, nil
container -> array, map

Adding a new scalar type is purely additive: declare a new typed slot and extend the case in Codec::ValueBridge (OCP).

Constant Summary collapse

SCALAR_TYPES =
%w[
  string integer float boolean date datetime symbol nil
].freeze
CONTAINER_TYPES =
%w[array map].freeze
ALL_TYPES =
(SCALAR_TYPES + CONTAINER_TYPES).freeze

Instance Attribute Summary

Attributes inherited from Base

#element_attributes, #id, #metadata_entries, #title

Instance Method Summary collapse

Methods inherited from Base

#accept, #attr, #flat_text, #metadata, #semantically_equivalent?, #set_attr, #set_metadata

Instance Method Details

#ruby_valueObject

Convenience: return the Ruby-native scalar value for this node, or nil for containers / nil-typed values. Used by callers that don’t care about the type discriminator.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/coradoc/core_model/frontmatter/frontmatter_value.rb', line 46

def ruby_value
  case value_type
  when 'string'   then string_value
  when 'integer'  then integer_value
  when 'float'    then float_value
  when 'boolean'  then boolean_value
  when 'date'     then date_value
  when 'datetime' then datetime_value
  when 'symbol'   then symbol_value
  when 'nil'      then nil
  end
end