Class: Uniword::Stylesets::YamlStyleSetLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/stylesets/yaml_styleset_loader.rb

Overview

Loads StyleSets from YAML files

Leverages lutaml-model’s from_yaml deserialization for simple, reliable loading of YAML StyleSet files.

Examples:

Load from YAML file

loader = YamlStyleSetLoader.new
styleset = loader.load('custom_styleset.yml')

Load bundled StyleSet

styleset = YamlStyleSetLoader.load_bundled('distinctive')

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_stylesetsArray<String>

List all available bundled StyleSets

Returns:

  • (Array<String>)

    StyleSet names



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

def self.available_stylesets
  styleset_dir = File.join(__dir__, "../../../data/stylesets")
  return [] unless Dir.exist?(styleset_dir)

  Dir.glob(File.join(styleset_dir, "*.yml")).map do |path|
    File.basename(path, ".yml")
  end.sort
end

.load_bundled(name) ⇒ StyleSet

Load bundled StyleSet by name

Parameters:

  • name (String)

    StyleSet name (e.g., ‘distinctive’, ‘basic’)

Returns:

Raises:

  • (ArgumentError)

    if StyleSet not found



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/uniword/stylesets/yaml_styleset_loader.rb', line 43

def self.load_bundled(name)
  styleset_dir = File.join(__dir__, "../../../data/stylesets")
  path = File.join(styleset_dir, "#{name}.yml")

  unless File.exist?(path)
    available = available_stylesets
    raise ArgumentError,
          "StyleSet '#{name}' not found. " \
          "Available StyleSets: #{available.join(', ')}"
  end

  new.load(path)
end

Instance Method Details

#load(path) ⇒ StyleSet

Load StyleSet from YAML file

Parameters:

  • path (String)

    Path to YAML file

Returns:



21
22
23
24
# File 'lib/uniword/stylesets/yaml_styleset_loader.rb', line 21

def load(path)
  # Use lutaml-model deserialization
  ::Uniword::StyleSet.from_yaml(File.read(path))
end