Class: Uniword::Stylesets::YamlStyleSetLoader
- Inherits:
-
Object
- Object
- Uniword::Stylesets::YamlStyleSetLoader
- 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.
Class Method Summary collapse
-
.available_stylesets ⇒ Array<String>
List all available bundled StyleSets.
-
.load_bundled(name) ⇒ StyleSet
Load bundled StyleSet by name.
Instance Method Summary collapse
-
#load(path) ⇒ StyleSet
Load StyleSet from YAML file.
Class Method Details
.available_stylesets ⇒ Array<String>
List all available bundled StyleSets
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
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 |