{"id":15403156,"url":"https://github.com/seuros/diagram-ruby","last_synced_at":"2026-03-04T20:32:51.068Z","repository":{"id":220727491,"uuid":"749192447","full_name":"seuros/diagram-ruby","owner":"seuros","description":null,"archived":false,"fork":false,"pushed_at":"2025-06-15T12:33:44.000Z","size":145,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-18T00:22:19.581Z","etag":null,"topics":["code-generation","developer-tools","diagram","dsl","framework","graph","ruby","ruby-gem","structure","visualization"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seuros.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-01-27T20:52:23.000Z","updated_at":"2026-01-05T23:18:47.000Z","dependencies_parsed_at":"2024-02-03T22:30:46.292Z","dependency_job_id":"21e825ac-39db-4dfe-86f0-38faec4fb341","html_url":"https://github.com/seuros/diagram-ruby","commit_stats":{"total_commits":8,"total_committers":2,"mean_commits":4.0,"dds":0.25,"last_synced_commit":"7ffcdbf04ce9b2b7359675be46f094131169bcc5"},"previous_names":["seuros/diagram-ruby"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/seuros/diagram-ruby","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seuros%2Fdiagram-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seuros%2Fdiagram-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seuros%2Fdiagram-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seuros%2Fdiagram-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seuros","download_url":"https://codeload.github.com/seuros/diagram-ruby/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seuros%2Fdiagram-ruby/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30091779,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-04T19:41:02.502Z","status":"ssl_error","status_checked_at":"2026-03-04T19:40:05.550Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","developer-tools","diagram","dsl","framework","graph","ruby","ruby-gem","structure","visualization"],"created_at":"2024-10-01T16:06:30.044Z","updated_at":"2026-03-04T20:32:49.950Z","avatar_url":"https://github.com/seuros.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Diagrams Gem\n\n[![Gem Version](https://badge.fury.io/rb/diagram.svg)](https://badge.fury.io/rb/diagram)\n\u003c!-- Add badges for Build Status, Code Climate, etc. once CI/analysis is set up --\u003e\n\n**Diagrams** provides Ruby objects for defining and manipulating various diagram types (Flowcharts, Class Diagrams, Gantt Charts, Pie Charts, State Diagrams). It focuses on the *data structure and logic*, allowing other tools or gems to handle rendering (e.g., to Mermaid, Graphviz, etc.).\n\n**Key Goals:**\n\n*   **Developer Experience \u0026 Extensibility:** Clean API, easy to extend.\n*   **Modern Ruby (3.3+):** Uses modern practices like RBS type signatures and `dry-rb` gems.\n*   **Uniform Capabilities:** Consistent serialization (Hash/JSON), comparison, versioning, and checksums across all diagram types.\n*   **Separation of Concerns:** Core gem handles data only, not rendering or persistence.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'diagram', '~\u003e 0.3.0' # Or appropriate version constraint\n```\n\nAnd then execute:\n\n```bash\nbundle install\n```\n\nOr install it yourself as:\n\n```bash\ngem install diagram\n```\n\n## Usage\n\n### Creating Diagrams\n\nRequire the gem and instantiate specific diagram classes.\n\n```ruby\nrequire 'diagram'\n\n# --- Flowchart Example ---\nflowchart = Diagrams::FlowchartDiagram.new(version: '1.0')\n\n# Create nodes (using Diagrams::Elements::Node)\nnode1 = Diagrams::Elements::Node.new(id: 'start', label: 'Start Process')\nnode2 = Diagrams::Elements::Node.new(id: 'step1', label: 'Do Something')\nnode3 = Diagrams::Elements::Node.new(id: 'end', label: 'End Process')\n\n# Add nodes to the diagram\nflowchart.add_node(node1)\nflowchart.add_node(node2)\nflowchart.add_node(node3)\n\n# Create and add edges (using Diagrams::Elements::Edge)\nedge1 = Diagrams::Elements::Edge.new(source_id: 'start', target_id: 'step1')\nedge2 = Diagrams::Elements::Edge.new(source_id: 'step1', target_id: 'end', label: 'Finished')\nflowchart.add_edge(edge1)\nflowchart.add_edge(edge2)\n\nputs \"Flowchart Nodes: #{flowchart.nodes.map(\u0026:id)}\"\n# =\u003e Flowchart Nodes: [\"start\", \"step1\", \"end\"]\n\n# --- Class Diagram Example ---\nclass_diagram = Diagrams::ClassDiagram.new(version: 2)\n\n# Create class entities (using Diagrams::Elements::ClassEntity)\nuser_class = Diagrams::Elements::ClassEntity.new(\n  name: 'User',\n  attributes: ['id: Integer', 'email: String'],\n  methods: ['authenticate(password: String): Boolean']\n)\norder_class = Diagrams::Elements::ClassEntity.new(\n  name: 'Order',\n  attributes: ['order_id: Integer', 'amount: Float']\n)\n\n# Add classes\nclass_diagram.add_class(user_class)\nclass_diagram.add_class(order_class)\n\n# Create and add relationships (using Diagrams::Elements::Relationship)\nrel = Diagrams::Elements::Relationship.new(\n  source_class_name: 'User',\n  target_class_name: 'Order',\n  type: 'has_many',\n  label: 'places'\n)\nclass_diagram.add_relationship(rel)\n\nputs \"Class Diagram Classes: #{class_diagram.classes.map(\u0026:name)}\"\n# =\u003e Class Diagram Classes: [\"User\", \"Order\"]\n\n# --- Pie Chart Example ---\npie_chart = Diagrams::PieDiagram.new(title: 'Browser Share', version: '2024-Q1')\n\n# Create and add slices (using Diagrams::Elements::Slice)\nslice1 = Diagrams::Elements::Slice.new(label: 'Chrome', value: 65.5)\nslice2 = Diagrams::Elements::Slice.new(label: 'Firefox', value: 15.0)\nslice3 = Diagrams::Elements::Slice.new(label: 'Safari', value: 10.5)\nslice4 = Diagrams::Elements::Slice.new(label: 'Edge', value: 5.0)\n# slice5 = Diagrams::Elements::Slice.new(label: 'Other', value: 4.0) # Total must be \u003c= 100\n\npie_chart.add_slice(slice1)\npie_chart.add_slice(slice2)\npie_chart.add_slice(slice3)\npie_chart.add_slice(slice4)\n# pie_chart.add_slice(slice5)\n\nputs \"Pie Chart Total: #{pie_chart.total_value}%\"\n# =\u003e Pie Chart Total: 96.0%\n\n# (Examples for Gantt and State diagrams can be added similarly)\n```\n\n### Serialization \u0026 Deserialization\n\nAll diagrams can be serialized to a Hash or JSON string, and deserialized back into objects.\n\n```ruby\n# Serialization\nflowchart_hash = flowchart.to_h\nflowchart_json = flowchart.to_json\n\nputs flowchart_json\n# =\u003e {\"type\":\"FlowchartDiagram\",\"version\":\"1.0\",\"checksum\":\"...\",\"data\":{\"nodes\":[...],\"edges\":[...]}}\n\n# Deserialization (using the Base class factory)\nloaded_flowchart = Diagrams::Base.from_json(flowchart_json)\n# or\n# loaded_flowchart = Diagrams::Base.from_hash(flowchart_hash)\n\nputs \"Loaded diagram type: #{loaded_flowchart.class}\"\n# =\u003e Loaded diagram type: Diagrams::FlowchartDiagram\nputs \"Loaded diagram version: #{loaded_flowchart.version}\"\n# =\u003e Loaded diagram version: 1.0\n\n# Verify content equality (ignores version)\noriginal_flowchart = Diagrams::FlowchartDiagram.new(\n  nodes: [node1, node2, node3],\n  edges: [edge1, edge2],\n  version: 'Different Version' # Version doesn't affect equality check\n)\nputs \"Diagrams have same content? #{loaded_flowchart == original_flowchart}\"\n# =\u003e Diagrams have same content? true\n```\n\n### Versioning and Checksums\n\nEach diagram has:\n\n*   `#version`: A user-managed field (passed during initialization) for tracking revisions.\n*   `#checksum`: An automatically calculated SHA256 hash of the diagram's content (nodes, edges, etc.). This changes whenever the content is modified via methods like `add_node`, `add_slice`, etc.\n\nYou can use the checksum to quickly detect if a diagram's content has changed. The `==` operator compares diagrams based on their type and checksum (content), ignoring the `version` field.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/diagrams/version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/seuros/diagram-ruby.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseuros%2Fdiagram-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseuros%2Fdiagram-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseuros%2Fdiagram-ruby/lists"}