### Install Mermaid Ruby Gem Manually Source: https://github.com/seuros/mermaid-ruby/blob/master/README.md Install the `diagram` and `mermaid` gems directly using the `gem install` command, useful for global installation or development. ```bash $ gem install diagram mermaid ``` -------------------------------- ### Install Mermaid Ruby Gem Dependencies via Bundler Source: https://github.com/seuros/mermaid-ruby/blob/master/README.md Execute `bundle install` in your terminal to install the gems listed in your Gemfile, ensuring all dependencies are met. ```bash $ bundle install ``` -------------------------------- ### Example Mermaid ERD Syntax Output Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/er_diagram_mermaid.md The Mermaid ERD syntax generated by the Ruby code, illustrating entity definitions with attributes and a relationship between CUSTOMER and ORDER. ```Mermaid erDiagram "CUSTOMER" { int id PK varchar name varchar email "Unique identifier" } "ORDER" { int id PK int customer_id FK datetime order_date } "CUSTOMER" }|--o{ "ORDER" : "places" ``` -------------------------------- ### Mermaid Gantt Chart Syntax Output Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/gantt_diagram_mermaid.md This snippet shows the Mermaid syntax generated by the Ruby code example. It represents a Gantt chart with a title and several tasks, each defined with an ID, name, start date, and end date. This syntax can be rendered by Mermaid-compatible viewers. ```Mermaid gantt title Software Project Timeline Design Phase :design, 2024-04-01, 2024-04-15 Backend Development :dev_be, 2024-04-16, 2024-05-10 Frontend Development :dev_fe, 2024-04-20, 2024-05-15 Testing :test, 2024-05-16, 2024-05-30 Deployment :deploy, 2024-06-01, 2024-06-05 ``` -------------------------------- ### Install Mermaid Ruby Gem with Diagram Base Source: https://github.com/seuros/mermaid-ruby/blob/master/README.md Add the `diagram` and `mermaid` gems to your application's Gemfile to include them as dependencies for generating Mermaid diagrams. ```ruby gem 'diagram' # The base gem for creating diagram objects gem 'mermaid' # This gem, for generating Mermaid syntax ``` -------------------------------- ### Define and Generate Complex Fantasy ERD in Ruby Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/er_diagram_mermaid.md A more elaborate example demonstrating the definition of multiple entities and various relationship types for a fantasy-themed ERD, showcasing the flexibility of the `diagrams` gem. ```Ruby # Code from test_complex_fantasy_erd in test/mermaid/er_diagram_test.rb diagram = Diagrams::ERDiagram.new # ... (Entity definitions as in the test) ... diagram.add_entity(name: 'WIZARD', attributes: [{ type: 'int', name: 'wizard_id', keys: [:PK] }, { type: 'string', name: 'name' }, { type: 'int', name: 'power_level' }]) diagram.add_entity(name: 'FAMILIAR', attributes: [{ type: 'int', name: 'familiar_id', keys: [:PK] }, { type: 'int', name: 'wizard_id', keys: [:FK] }, { type: 'string', name: 'species' }, { type: 'string', name: 'name' }]) # ... (add all other entities) ... diagram.add_entity(name: 'CLASS', attributes: [{ type: 'int', name: 'class_id', keys: [:PK] }, { type: 'string', name: 'name' }, { type: 'string', name: 'primary_stat' }]) # ... (Relationship definitions as in the test) ... diagram.add_relationship(entity1: 'WIZARD', entity2: 'FAMILIAR', cardinality1: :ONE_ONLY, cardinality2: :ONE_ONLY, identifying: false, label: 'has exactly one') diagram.add_relationship(entity1: 'SPELLBOOK', entity2: 'SPELL', cardinality1: :ONE_ONLY, cardinality2: :ZERO_OR_MORE, identifying: false, label: 'contains many') # ... (add all other relationships) ... diagram.add_relationship(entity1: 'RACE', entity2: 'CLASS', cardinality1: :ONE_OR_MORE, cardinality2: :ONE_OR_MORE, identifying: true, label: 'can choose') puts diagram.to_mermaid ``` -------------------------------- ### Mermaid Class Diagram Syntax Output Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/class_diagram_mermaid.md This snippet shows the Mermaid syntax generated by the Ruby code example. It represents a class diagram with `Animal`, `Dog`, `Cat`, and `Owner` classes, including their attributes, methods, and defined relationships (inheritance and association with cardinality). ```Mermaid classDiagram class Animal { -String name +int age +makeSound() void } class Dog { +String breed +bark() void +fetch() void } class Cat { -boolean hasClaws +meow() void } class Owner { +String name +walkPet(Animal pet) void } Dog <|-- Animal Cat <|-- Animal Owner --> Animal : owns > ``` -------------------------------- ### Generate Mermaid Pie Chart Syntax in Ruby Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/pie_diagram_mermaid.md This Ruby code demonstrates how to define slices, create a Diagrams::PieDiagram object with a title and slices, and then use the to_mermaid method (provided by the mermaid-ruby gem) to generate the corresponding Mermaid pie chart syntax. It requires the 'diagrams' and 'mermaid' gems. ```ruby require 'diagrams' require 'mermaid' # Applies the #to_mermaid patch # Define slices slice1 = Diagrams::Elements::Slice.new(label: 'Residential', value: 45.5) slice2 = Diagrams::Elements::Slice.new(label: 'Commercial', value: 30) slice3 = Diagrams::Elements::Slice.new(label: 'Industrial', value: 15) slice4 = Diagrams::Elements::Slice.new(label: 'Agricultural', value: 9.5) # Create diagram diagram = Diagrams::PieDiagram.new( title: 'Land Usage Distribution (2024)', slices: [slice1, slice2, slice3, slice4] ) # Generate Mermaid syntax mermaid_output = diagram.to_mermaid puts mermaid_output ``` -------------------------------- ### Generate Mermaid Pie Chart from Ruby Objects Source: https://github.com/seuros/mermaid-ruby/blob/master/README.md Demonstrates creating a pie chart with a title and slices using `diagrams` gem and rendering it as Mermaid pie chart syntax. ```ruby # --- Example: Pie Chart --- slice1 = Diagrams::Elements::Slice.new(label: 'Work', value: 8) slice2 = Diagrams::Elements::Slice.new(label: 'Sleep', value: 8) slice3 = Diagrams::Elements::Slice.new(label: 'Play', value: 8) pie_chart = Diagrams::PieDiagram.new(title: 'Daily Routine', slices: [slice1, slice2, slice3]) puts pie_chart.to_mermaid # Output: # pie # title Daily Routine # "Work" : 8 # "Sleep" : 8 # "Play" : 8 ``` -------------------------------- ### Generate Mermaid State Diagram from Ruby Objects Source: https://github.com/seuros/mermaid-ruby/blob/master/README.md Demonstrates how to create a state diagram using `diagrams` gem elements and then convert it into Mermaid syntax using the `#to_mermaid` method provided by the `mermaid` gem. It shows states and transitions. ```ruby require 'diagrams' require 'mermaid' # This applies the patches # --- Example: State Diagram --- state_a = Diagrams::Elements::State.new(id: 'A', label: 'State A') state_b = Diagrams::Elements::State.new(id: 'B') transition1 = Diagrams::Elements::Transition.new(source_state_id: '*', target_state_id: 'A') transition2 = Diagrams::Elements::Transition.new(source_state_id: 'A', target_state_id: 'B', label: 'Event X') state_diagram = Diagrams::StateDiagram.new( states: [state_a, state_b], transitions: [transition1, transition2] ) puts state_diagram.to_mermaid # Output: # stateDiagram-v2 # A : State A # [*] --> A # A --> B : Event X ``` -------------------------------- ### Generate Mermaid Gantt Chart from Ruby Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/gantt_diagram_mermaid.md This Ruby code demonstrates how to define tasks using `Diagrams::Elements::Task` objects, create a `Diagrams::GanttDiagram`, and then convert it into Mermaid syntax using the `#to_mermaid` method provided by the `mermaid-ruby` gem. It requires the `diagrams` and `mermaid-ruby` gems. The output is printed to the console. ```Ruby require 'diagrams' require 'mermaid' # Applies the #to_mermaid patch # Define tasks # Note: diagram gem currently only supports start/end dates, not durations or sections. task_design = Diagrams::Elements::Task.new( id: 'design', name: 'Design Phase', start_date: '2024-04-01', end_date: '2024-04-15' ) task_dev_be = Diagrams::Elements::Task.new( id: 'dev_be', name: 'Backend Development', start_date: '2024-04-16', end_date: '2024-05-10' ) task_dev_fe = Diagrams::Elements::Task.new( id: 'dev_fe', name: 'Frontend Development', start_date: '2024-04-20', # Starts slightly after backend end_date: '2024-05-15' ) task_test = Diagrams::Elements::Task.new( id: 'test', name: 'Testing', start_date: '2024-05-16', end_date: '2024-05-30' ) task_deploy = Diagrams::Elements::Task.new( id: 'deploy', name: 'Deployment', start_date: '2024-06-01', end_date: '2024-06-05' ) # Create diagram diagram = Diagrams::GanttDiagram.new( title: 'Software Project Timeline', tasks: [task_design, task_dev_be, task_dev_fe, task_test, task_deploy] ) # Generate Mermaid syntax mermaid_output = diagram.to_mermaid puts mermaid_output ``` -------------------------------- ### Generate Gitgraph Diagram with Ruby Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/gitgraph_diagram_mermaid.md This Ruby code demonstrates how to use the 'diagrams' and 'mermaid-ruby' gems to create a Gitgraph diagram. It shows various Git operations like commits, branches, checkouts, and merges, finally generating the Mermaid syntax using the #to_mermaid method. ```ruby require 'diagrams' require 'mermaid' # Applies the #to_mermaid patch # Create diagram and perform git operations diagram = Diagrams::GitgraphDiagram.new # Initial commit on main diagram.commit(id: 'c1', message: 'Initial commit') # Create develop branch and commit diagram.branch(name: 'develop') # Checks out develop automatically diagram.commit(id: 'c2', message: 'Add feature A') # Commit on main diagram.checkout(name: 'main') diagram.commit(id: 'c3', message: 'Fix critical bug', tag: 'v1.0') # Create feature branch from develop diagram.checkout(name: 'develop') diagram.branch(name: 'feature/b') # Checks out feature/b diagram.commit(id: 'c4', message: 'Implement feature B') # Merge feature/b back to develop diagram.checkout(name: 'develop') diagram.merge(from_branch_name: 'feature/b', id: 'm1', message: 'Merge feature B') # Commit on develop diagram.commit(id: 'c5', message: 'Refactor feature A') # Merge develop into main diagram.checkout(name: 'main') diagram.merge(from_branch_name: 'develop', id: 'm2', tag: 'v1.1') # Generate Mermaid syntax mermaid_output = diagram.to_mermaid puts mermaid_output ``` -------------------------------- ### Generate Mermaid Gantt Chart from Ruby Objects Source: https://github.com/seuros/mermaid-ruby/blob/master/README.md Illustrates how to create a Gantt chart with a title and tasks using `diagrams` gem and convert it to Mermaid Gantt chart syntax. ```ruby # --- Example: Gantt Chart --- gantt_chart = Diagrams::GanttDiagram.new(title: 'Project Timeline') gantt_chart.add_task(id: 't1', label: 'Phase 1', start: '2024-01-01', duration: '10d') gantt_chart.add_task(id: 't2', label: 'Phase 2', start: '2024-01-11', duration: '10d') puts gantt_chart.to_mermaid # Output: # gantt # title Project Timeline # section Default Section # Phase 1 :t1, 2024-01-01, 10d # Phase 2 :t2, 2024-01-11, 10d ``` -------------------------------- ### Define and Generate Mermaid State Diagram in Ruby Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/state_diagram_mermaid.md This Ruby code snippet demonstrates how to use the `diagrams` and `mermaid-ruby` gems to programmatically define states and transitions for a state diagram. It then generates the corresponding Mermaid syntax using the `to_mermaid` method, which can be used to visualize the diagram. ```Ruby require 'diagrams' require 'mermaid' # Applies the #to_mermaid patch # Define states idle = Diagrams::Elements::State.new(id: 'Idle') fteching = Diagrams::Elements::State.new(id: 'Fetching', label: 'Fetching Data') processing = Diagrams::Elements::State.new(id: 'Processing') error_state = Diagrams::Elements::State.new(id: 'Error', label: 'Error Occurred') done = Diagrams::Elements::State.new(id: 'Done') # Define transitions t1 = Diagrams::Elements::Transition.new(source_state_id: '*', target_state_id: 'Idle') # Start state t2 = Diagrams::Elements::Transition.new(source_state_id: 'Idle', target_state_id: 'Fetching', label: 'Fetch Request') t3 = Diagrams::Elements::Transition.new(source_state_id: 'Fetching', target_state_id: 'Processing', label: 'Data Received') t4 = Diagrams::Elements::Transition.new(source_state_id: 'Fetching', target_state_id: 'Error', label: 'Fetch Failed') t5 = Diagrams::Elements::Transition.new(source_state_id: 'Processing', target_state_id: 'Done', label: 'Process OK') t6 = Diagrams::Elements::Transition.new(source_state_id: 'Processing', target_state_id: 'Error', label: 'Process Failed') t7 = Diagrams::Elements::Transition.new(source_state_id: 'Error', target_state_id: 'Idle', label: 'Reset') t8 = Diagrams::Elements::Transition.new(source_state_id: 'Done', target_state_id: 'Idle', label: 'New Request / Timeout') t9 = Diagrams::Elements::Transition.new(source_state_id: 'Done', target_state_id: '*') # End state # Create diagram diagram = Diagrams::StateDiagram.new( states: [idle, fetching, processing, error_state, done], transitions: [t1, t2, t3, t4, t5, t6, t7, t8, t9] ) # Generate Mermaid syntax mermaid_output = diagram.to_mermaid puts mermaid_output ``` -------------------------------- ### Mermaid Pie Chart Syntax Output Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/pie_diagram_mermaid.md This snippet shows the Mermaid syntax generated by the Ruby code for a pie chart. It defines a title and several slices with their respective labels and values, ready to be rendered by a Mermaid-compatible viewer. ```mermaid pie title Land Usage Distribution (2024) "Residential" : 45.5 "Commercial" : 30 "Industrial" : 15 "Agricultural" : 9.5 ``` -------------------------------- ### Define and Generate Basic Mermaid ERD in Ruby Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/er_diagram_mermaid.md Demonstrates how to create an `ERDiagram` object, add entities with attributes (including primary and foreign keys), define relationships with cardinalities and labels, and finally generate the Mermaid syntax using `to_mermaid`. ```Ruby # Create the diagram object diagram = Diagrams::ERDiagram.new # Add entities diagram.add_entity( name: 'CUSTOMER', attributes: [ { type: 'int', name: 'id', keys: [:PK] }, { type: 'varchar', name: 'name' }, { type: 'varchar', name: 'email', comment: 'Unique identifier' } ] ) diagram.add_entity( name: 'ORDER', attributes: [ { type: 'int', name: 'id', keys: [:PK] }, { type: 'int', name: 'customer_id', keys: [:FK] }, { type: 'datetime', name: 'order_date' } ] ) # Add a relationship # Cardinality symbols: :ZERO_OR_ONE, :ONE_ONLY, :ZERO_OR_MORE, :ONE_OR_MORE # Identifying: true (solid line) or false (dashed line) diagram.add_relationship( entity1: 'CUSTOMER', entity2: 'ORDER', cardinality1: :ONE_OR_MORE, cardinality2: :ZERO_OR_MORE, identifying: true, # Identifying relationship label: 'places' ) # Generate Mermaid syntax puts diagram.to_mermaid ``` -------------------------------- ### Generate Mermaid Flowchart from Ruby Objects Source: https://github.com/seuros/mermaid-ruby/blob/master/README.md Shows how to construct a simple flowchart with nodes and edges using `diagrams` gem and convert it to Mermaid flowchart syntax. ```ruby # --- Example: Flowchart --- node1 = Diagrams::Elements::Node.new(id: 'n1', label: 'Start') node2 = Diagrams::Elements::Node.new(id: 'n2', label: 'Process') edge1 = Diagrams::Elements::Edge.new(source_id: 'n1', target_id: 'n2', label: 'Go') flowchart = Diagrams::FlowchartDiagram.new(nodes: [node1, node2], edges: [edge1]) puts flowchart.to_mermaid # Output: # graph TD # n1["Start"] # n2["Process"] # n1 -- "Go" --> n2 ``` -------------------------------- ### Generate Mermaid Class Diagram from Ruby Objects Source: https://github.com/seuros/mermaid-ruby/blob/master/README.md Illustrates the creation of a class diagram with classes, attributes, methods, and relationships using `diagrams` gem, then renders it to Mermaid syntax. ```ruby # --- Example: Class Diagram --- class_animal = Diagrams::Elements::ClassEntity.new(name: 'Animal', attributes: ['+String name']) class_dog = Diagrams::Elements::ClassEntity.new(name: 'Dog', attributes: ['+String breed'], methods: ['+bark() void']) rel_inheritance = Diagrams::Elements::Relationship.new( source_class_name: 'Dog', target_class_name: 'Animal', type: 'inheritance' ) class_diagram = Diagrams::ClassDiagram.new( classes: [class_animal, class_dog], relationships: [rel_inheritance] ) puts class_diagram.to_mermaid # Output: # classDiagram # class Animal { # +String name # } # class Dog { # +String breed # +bark() void # } # Dog <|-- Animal ``` -------------------------------- ### Mermaid Syntax for Web Browser Timeline Diagram Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/timeline_diagram_mermaid.md This is the Mermaid syntax generated by the Ruby code, representing a timeline diagram of web browser history. It defines sections and events with their respective years, ready to be rendered by a Mermaid compatible viewer. ```Mermaid timeline title History of Web Browsers section Early Days 1990 : WorldWideWeb (Nexus) 1993 : Mosaic 1994 : Netscape Navigator : Internet Explorer 1 section Browser Wars 1997 : IE 4 1998 : Netscape Communicator 4.5 : Mozilla Project starts 2002 : Mozilla 1.0 2004 : Firefox 1.0 section Modern Era 2008 : Google Chrome 2013 : IE 11 (Last version) 2015 : Microsoft Edge ``` -------------------------------- ### Generate Mermaid Flowchart using Ruby Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/flowchart_diagram_mermaid.md This Ruby code demonstrates how to define nodes and edges for a flowchart using the 'diagrams' gem and then generate Mermaid syntax using the 'mermaid-ruby' gem's #to_mermaid method. It shows the programmatic construction of a flowchart diagram. ```Ruby require 'diagrams' require 'mermaid' # Applies the #to_mermaid patch # Define nodes start_node = Diagrams::Elements::Node.new(id: 'start', label: 'Start Process') input_node = Diagrams::Elements::Node.new(id: 'input', label: 'Get User Input') # Node shapes are not directly supported by diagram gem's Node, # Mermaid output uses default rectangle shape: id["label"] decision_node = Diagrams::Elements::Node.new(id: 'decide', label: 'Is Data Valid?') process_a = Diagrams::Elements::Node.new(id: 'proc_a', label: 'Process A (Valid)') process_b = Diagrams::Elements::Node.new(id: 'proc_b', label: 'Process B (Invalid)') end_node = Diagrams::Elements::Node.new(id: 'end_node', label: 'End Process') # Changed ID to end_node # Define edges edge1 = Diagrams::Elements::Edge.new(source_id: 'start', target_id: 'input') edge2 = Diagrams::Elements::Edge.new(source_id: 'input', target_id: 'decide') edge3 = Diagrams::Elements::Edge.new(source_id: 'decide', target_id: 'proc_a', label: 'Yes') edge4 = Diagrams::Elements::Edge.new(source_id: 'decide', target_id: 'proc_b', label: 'No') edge5 = Diagrams::Elements::Edge.new(source_id: 'proc_a', target_id: 'end_node') # Updated target_id edge6 = Diagrams::Elements::Edge.new(source_id: 'proc_b', target_id: 'end_node') # Updated target_id # Create diagram diagram = Diagrams::FlowchartDiagram.new( nodes: [start_node, input_node, decision_node, process_a, process_b, end_node], edges: [edge1, edge2, edge3, edge4, edge5, edge6] ) # Generate Mermaid syntax mermaid_output = diagram.to_mermaid puts mermaid_output ``` -------------------------------- ### Generate Mermaid Timeline Diagram with Ruby Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/timeline_diagram_mermaid.md This Ruby code demonstrates how to use the `diagrams` and `mermaid-ruby` gems to create a `TimelineDiagram` object. It adds sections and historical events related to web browsers, then generates and prints the corresponding Mermaid syntax using the `#to_mermaid` method. ```Ruby require 'diagrams' require 'mermaid' # Applies the #to_mermaid patch # Create diagram diagram = Diagrams::TimelineDiagram.new(title: 'History of Web Browsers') # Add sections and periods/events diagram.add_section('Early Days') diagram.add_period(period_label: '1990', events: 'WorldWideWeb (Nexus)') diagram.add_period(period_label: '1993', events: 'Mosaic') diagram.add_period(period_label: '1994', events: ['Netscape Navigator', 'Internet Explorer 1']) diagram.add_section('Browser Wars') diagram.add_period(period_label: '1997', events: 'IE 4') diagram.add_period(period_label: '1998', events: ['Netscape Communicator 4.5', 'Mozilla Project starts']) diagram.add_period(period_label: '2002', events: 'Mozilla 1.0') diagram.add_period(period_label: '2004', events: 'Firefox 1.0') diagram.add_section('Modern Era') diagram.add_period(period_label: '2008', events: 'Google Chrome') diagram.add_period(period_label: '2013', events: 'IE 11 (Last version)') diagram.add_period(period_label: '2015', events: 'Microsoft Edge') # Generate Mermaid syntax mermaid_output = diagram.to_mermaid puts mermaid_output ``` -------------------------------- ### Mermaid Gitgraph Syntax Output Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/gitgraph_diagram_mermaid.md This is the Mermaid syntax generated by the Ruby code, representing the Git operations performed. It can be rendered by a Mermaid-compatible viewer to visualize the Git history. ```mermaid gitGraph checkout main commit id: "c1" branch develop checkout develop commit id: "c2" checkout main commit id: "c3" tag: "v1.0" checkout develop branch feature/b checkout feature/b commit id: "c4" checkout develop merge feature/b id: "m1" commit id: "c5" checkout main merge develop id: "m2" tag: "v1.1" ``` -------------------------------- ### Require Ruby Gems for Mermaid ERD Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/er_diagram_mermaid.md Includes the necessary `diagrams` and `mermaid-ruby` gems to enable ERD generation and Mermaid rendering capabilities. ```Ruby require 'diagrams' require 'mermaid' ``` -------------------------------- ### Generated Mermaid State Diagram Syntax Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/state_diagram_mermaid.md This code block shows the Mermaid syntax generated by the Ruby script. This syntax can be directly rendered by Mermaid to visualize the state diagram defined in the Ruby code. ```Mermaid stateDiagram-v2 Fetching : Fetching Data Error : Error Occurred [*] --> Idle Idle --> Fetching : Fetch Request Fetching --> Processing : Data Received Fetching --> Error : Fetch Failed Processing --> Done : Process OK Processing --> Error : Process Failed Error --> Idle : Reset Done --> Idle : New Request / Timeout Done --> [*] ``` -------------------------------- ### Generate Mermaid Class Diagram from Ruby Objects Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/class_diagram_mermaid.md This Ruby code demonstrates how to define class entities and relationships using the `diagrams` gem, then generate a Mermaid class diagram string using the `mermaid-ruby` gem's `to_mermaid` method. It shows the creation of classes, attributes, methods, and different types of relationships (inheritance, association). ```Ruby require 'diagrams' require 'mermaid' # Applies the #to_mermaid patch # Define classes with attributes and methods as strings animal = Diagrams::Elements::ClassEntity.new( name: 'Animal', attributes: ['-String name', '+int age'], methods: ['+makeSound() void'] ) dog = Diagrams::Elements::ClassEntity.new( name: 'Dog', attributes: ['+String breed'], methods: ['+bark() void', '+fetch() void'] ) cat = Diagrams::Elements::ClassEntity.new( name: 'Cat', attributes: ['-boolean hasClaws'], methods: ['+meow() void'] ) owner = Diagrams::Elements::ClassEntity.new( name: 'Owner', attributes: ['+String name'], methods: ['+walkPet(Animal pet) void'] ) # Define relationships rel1 = Diagrams::Elements::Relationship.new(source_class_name: 'Dog', target_class_name: 'Animal', type: 'inheritance') rel2 = Diagrams::Elements::Relationship.new(source_class_name: 'Cat', target_class_name: 'Animal', type: 'inheritance') rel3 = Diagrams::Elements::Relationship.new(source_class_name: 'Owner', target_class_name: 'Animal', type: 'association', label: 'owns >') # Cardinality/direction example # Create diagram diagram = Diagrams::ClassDiagram.new( classes: [animal, dog, cat, owner], relationships: [rel1, rel2, rel3] ) # Generate Mermaid syntax mermaid_output = diagram.to_mermaid puts mermaid_output ``` -------------------------------- ### Mermaid Flowchart Syntax Output Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/flowchart_diagram_mermaid.md This is the Mermaid syntax generated by the Ruby code snippet. It defines a flowchart with various nodes and directed edges, including conditional paths, ready to be rendered by a Mermaid viewer. ```Mermaid graph TD start["Start Process"] input["Get User Input"] decide["Is Data Valid?"] proc_a["Process A (Valid)"] proc_b["Process B (Invalid)"] end_node["End Process"] start --> input input --> decide decide -- "Yes" --> proc_a decide -- "No" --> proc_b proc_a --> end_node proc_b --> end_node ``` -------------------------------- ### Complex Entity-Relationship Diagram for a Fantasy World Source: https://github.com/seuros/mermaid-ruby/blob/master/docs/er_diagram_mermaid.md This Mermaid ER diagram illustrates a comprehensive database schema for a fantasy setting, defining entities such as Wizards, Familiars, Spells, Potions, Adventurers, and their intricate relationships. It showcases one-to-one, one-to-many, and many-to-many relationships with specific cardinality notations. ```mermaid erDiagram "WIZARD" { int wizard_id PK string name int power_level } "FAMILIAR" { int familiar_id PK int wizard_id FK string species string name } "SPELLBOOK" { int book_id PK string title int wizard_id FK } "SPELL" { int spell_id PK int book_id FK string name string effect } "POTION" { int potion_id PK int alchemist_id FK string effect int potency } "ALCHEMIST" { int alchemist_id PK string name int skill_level } "ADVENTURER" { int adventurer_id PK string name string class } "QUEST" { int quest_id PK string title string description } "ARTIFACT" { int artifact_id PK int guardian_id FK string name string power } "GUARDIAN" { int guardian_id PK string type int strength } "DRAGON" { int dragon_id PK string name string color } "TREASURE" { int treasure_id PK int dragon_id FK string type int value } "GUILD" { int guild_id PK string name string location } "MEMBER" { int member_id PK int guild_id FK string name string rank } "KINGDOM" { int kingdom_id PK string name string ruler } "PROVINCE" { int province_id PK int kingdom_id FK string name string governor } "ENCHANTMENT" { int enchantment_id PK string type int power } "ITEM" { int item_id PK int enchantment_id FK string name string rarity } "MENTOR" { int mentor_id PK string name int wisdom } "APPRENTICE" { int apprentice_id PK int mentor_id FK string name int potential } "FACTION" { int faction_id PK string name string alignment } "FACTION_MEMBER" { int member_id PK int faction_id FK string name string role } "RACE" { int race_id PK string name int lifespan } "CLASS" { int class_id PK string name string primary_stat } "WIZARD" ||--|| "FAMILIAR" : "has exactly one" "SPELLBOOK" ||--o{ "SPELL" : "contains many" "POTION" }o--|| "ALCHEMIST" : "created by one" "ADVENTURER" }o--o{ "QUEST" : "undertakes many" "ARTIFACT" |o--|| "GUARDIAN" : "protected by one" "DRAGON" |o--o{ "TREASURE" : "hoards many" "GUILD" ||--o{ "MEMBER" : "may have members" "KINGDOM" ||--|{ "PROVINCE" : "rules at least one" "ENCHANTMENT" |o--o{ "ITEM" : "may enhance" "MENTOR" |o--|{ "APPRENTICE" : "trains at least one" "FACTION" ||--o{ "FACTION_MEMBER" : "has" "RACE" }|--|{ "CLASS" : "can choose" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.