lutaml / expressir

Ruby parser for the ISO EXPRESS language
3 stars 3 forks source link

Add a `select_proc` argument for `ModelElement#to_hash` to allow filtering out things #153

Closed ronaldtse closed 6 months ago

ronaldtse commented 6 months ago

Like this:

schema_paths = YAML.load_file('documents/iso-10303-41/schemas.yaml')['schemas'].map {|x,y| y['path'].gsub("../../", "")}

repo = Expressir::Express::Parser.from_files(schema_paths); 1

filtered_schemas = ["action_schema", "date_time_schema"]
select_proc = Proc.new do |value|
  if value.is_a?(Expressir::Model::Declarations::Schema)
    filtered_schemas.include?(value.id)
  else
    true
  end
end

y = repo.to_hash(select_proc: select_proc)

schemas = y['schemas']
schemas.map {|s| s["id"] }