Skip to content

Instantly share code, notes, and snippets.

@localhostdotdev
Created May 7, 2019 00:03
Show Gist options
  • Save localhostdotdev/659f4c5371d9a2649cda262141c9a88f to your computer and use it in GitHub Desktop.
Save localhostdotdev/659f4c5371d9a2649cda262141c9a88f to your computer and use it in GitHub Desktop.

Revisions

  1. localhostdotdev created this gist May 7, 2019.
    43 changes: 43 additions & 0 deletions graph + ruby code.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    ![graphiz nodes](https://i.imgur.com/b4Ft6DQ.png)

    ```ruby
    puts Contact.all.map { |c| "C#{c.id} [style=filled,color=greenyellow]" } +
    Book.all.map { |b| "B#{b.id} [style=filled,color=lightcyan]" } +
    BookContact.all.map { |bc| "C#{bc.contact_id} -> B#{bc.book_id}" }
    ```

    ```graphiz
    digraph G {
    C1 [style=filled,color=greenyellow]
    C2 [style=filled,color=greenyellow]
    C3 [style=filled,color=greenyellow]
    C4 [style=filled,color=greenyellow]
    C5 [style=filled,color=greenyellow]
    C6 [style=filled,color=greenyellow]
    C7 [style=filled,color=greenyellow]
    C8 [style=filled,color=greenyellow]
    C9 [style=filled,color=greenyellow]
    C10 [style=filled,color=greenyellow]
    B1 [style=filled,color=lightcyan]
    B2 [style=filled,color=lightcyan]
    B3 [style=filled,color=lightcyan]
    B4 [style=filled,color=lightcyan]
    B5 [style=filled,color=lightcyan]
    B6 [style=filled,color=lightcyan]
    C1 -> B1
    C2 -> B1
    C1 -> B2
    C2 -> B2
    C3 -> B2
    C4 -> B2
    C4 -> B3
    C5 -> B3
    C6 -> B3
    C3 -> B4
    C4 -> B4
    C5 -> B4
    C6 -> B4
    C1 -> B1
    C10 -> B1
    }
    ```