Project

yuml

0.0
No commit activity in last 3 years
No release in over 3 years
A Ruby DSL for generating UML built on yuml.me
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 3.4
 Project Readme

The UML DSL

A Ruby DSL for generating UML built on yuml.me, visit the homepage to learn more.

Getting Started

To build a UML document start with this block of code. Everything inside the block will be used to describe the uml document you want to create.

require 'yuml'

YUML.generate(file: 'tmp.pdf') do |uml|
  ...
end

Generating a Class

To generate a class for the document use uml.class and pass a code block in to configure it. It accepts the following methods for configuration.

  • name(name = nil, prototype = nil) (required)
  • variables(*args)
  • methods(*args)

Example

document = uml.class do
  name 'Document'
  variables '-title: String', '-body: String'
  methods(
    '+add_section(id: int, content: String, style: Symbol)',
    '+remove_section(id: int)',
    '+edit_section(id: int, content: String, style: Symbol)'
  )
end
shape = uml.class do
  name 'Shape', 'module'
  methods '+draw(id: int, content: String, style: Symbol)'
end

Adding Relationships

After generating some classes to add relationships to them use the following YUML::Class methods.

  • has_a(node, options = {})
  • is_a(node, options = {})
  • associated_with(node, options = {})
  • attach_note(content, options = {}) *options include color!

has_a can be composition or aggregation but defaults to aggregation.

is_a can be inheritance or interface but defaults to inheritance.

associated_with can be association, directed_association, two_way_association, or dependancy but defaults to directed_association.

Example

document.has_a(picture, cardinality: '0..*')
document.is_a(content)

picture.is_a(content, type: :interface)
content.associated_with(content, type: :association, cardinality: %w(uses used))
document.attach_note('This is a document', 'green')

Adding notes

You can add notes to the document itself as well as attached to a class

YUML.generate(file: 'tmp.pd') do |uml|
  uml.attach_note('Cool UML Tool?')
end

Test it Out

require 'yuml'

YUML.generate(file: 'example.pdf') do |uml|
  document = uml.class do
    name 'Document'
    variables '-title: String', '-body: String'
    methods(
      '+add_section(id: int, content: String, style: Symbol)',
      '+remove_section(id: int)',
      '+edit_section(id: int, content: String, style: Symbol)'
    )
  end

  picture = uml.class do
    name 'Picture'
  end

  content = uml.class do
    name 'Content'
  end

  document.has_a(picture, cardinality: '0..*')
  document.is_a(content)

  picture.is_a(content)
end

output