diagram 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c99defb74ddced6d50a0dd2bd5cf61b90ce2edab9192c5f119586442eb625d12
4
- data.tar.gz: 1bd666eed832e6052f789c3a37fd634d2cb4c198468281bafc17bc1ca500d05a
3
+ metadata.gz: 22a26c92b613b6357a345213015ddb7d2a26273b8e7e6c1f8611adddee2016a8
4
+ data.tar.gz: ca84223561bac7932932a62223ec5215e548d7d7fe0b6a0152603941936fc6b8
5
5
  SHA512:
6
- metadata.gz: f9d0b5269c5093821a09140273590af586dc35e4a21b9aed5c45a5201db8ebcfdb769e3764038fe0a74e467eea3d18e1f1fc970c295e69fefbdc686230106b48
7
- data.tar.gz: 7a53a67aecab0fa28adee1e6f826114ad0f0184e994e31c346d9b3224a4fd72e255ed4eaea714327c467664cef766ae2da1cbded21c58d620d7cb5862c65617d
6
+ metadata.gz: e19963f33267bb05a8e6b699101b61115927e37c8301dab49ae4f3d1e51f6b2146c6f5ff3ba3d318293c11009b0b528c535e7809dff11cc61757f72fd0aaec1b
7
+ data.tar.gz: 0a2190bbe2dad110325ac13271eb2dfccf32b7009bdc10ece7117677e4f8fd819e2d4b4ae063c5175c400816d0f743aed5f4b448c685f78cd17c0347d1f64d39
@@ -12,8 +12,8 @@ module Diagrams
12
12
  # @param version [String, Integer, nil] User-defined version identifier.
13
13
  def initialize(classes: [], relationships: [], version: 1)
14
14
  super(version:)
15
- @classes = classes.is_a?(Array) ? classes : []
16
- @relationships = relationships.is_a?(Array) ? relationships : []
15
+ @classes = Array(classes)
16
+ @relationships = Array(relationships)
17
17
  validate_elements!
18
18
  update_checksum!
19
19
  end
@@ -10,15 +10,22 @@ module Diagrams
10
10
  # Name of the class
11
11
  attribute :name, Types::Strict::String.constrained(min_size: 1)
12
12
 
13
- # List of attributes (e.g., "id: Integer", "name: String")
13
+ # List of attributes (e.g., "id: Integer", "name: String") # Maybe this need renaming to "fields"?
14
14
  attribute :attributes, Types::Strict::Array.of(Types::Strict::String).default([].freeze)
15
15
 
16
- # List of methods (e.g., "save()", "find(id: Integer)")
16
+ # List of methods (e.g., "save()", "find(id: Integer)") # Maybe this need renaming to "functions"?
17
17
  attribute :methods, Types::Strict::Array.of(Types::Strict::String).default([].freeze)
18
18
 
19
19
  # Returns a hash representation suitable for serialization.
20
20
  #
21
21
  # @return [Hash{Symbol => String | Array<String>}]
22
+ def to_h
23
+ {
24
+ name:,
25
+ attributes: self[:attributes],
26
+ methods: self[:methods]
27
+ }
28
+ end
22
29
  end
23
30
  end
24
31
  end
@@ -19,8 +19,7 @@ module Diagrams
19
19
  #
20
20
  # @return [Hash{Symbol => String | nil}]
21
21
  def to_h
22
- # Rely on Dry::Struct's default to_h, which includes all attributes.
23
- # Filter out nil label if desired.
22
+ # Start with Dry::Struct's hash and drop nil attributes.
24
23
  super.compact
25
24
  end
26
25
  end
@@ -14,7 +14,7 @@ module Diagrams
14
14
  #
15
15
  # @return [Hash{Symbol => String | nil}]
16
16
  def to_h
17
- # Rely on Dry::Struct's default to_h, filtering out nil label.
17
+ # Start with Dry::Struct's hash and drop nil attributes.
18
18
  super.compact
19
19
  end
20
20
  end
@@ -15,7 +15,6 @@ module Diagrams
15
15
  attribute :cherry_pick_source_id, Types::Strict::String.optional.default(nil)
16
16
 
17
17
  # Returns a hash representation suitable for serialization.
18
- # Dry::Struct provides to_h, but explicit definition ensures desired keys/structure.
19
18
  # Optional attributes are included only if they have non-nil values.
20
19
  #
21
20
  # @return [Hash{Symbol => String | Array<String> | Symbol}]
@@ -21,9 +21,6 @@ module Diagrams
21
21
  id:,
22
22
  label:
23
23
  }
24
- # Dry::Struct automatically provides a to_h method,
25
- # but defining it explicitly ensures the desired structure.
26
- # super # Alternatively, call super if the default is sufficient.
27
24
  end
28
25
  end
29
26
  end
@@ -25,7 +25,7 @@ module Diagrams
25
25
  #
26
26
  # @return [Hash{Symbol => String | nil}]
27
27
  def to_h
28
- # Rely on Dry::Struct's default to_h, filtering out nil label.
28
+ # Start with Dry::Struct's hash and drop nil attributes.
29
29
  super.compact
30
30
  end
31
31
  end
@@ -18,6 +18,14 @@ module Diagrams
18
18
  # Returns a hash representation suitable for serialization.
19
19
  #
20
20
  # @return [Hash{Symbol => String | Float | nil}]
21
+ def to_h
22
+ hash = {
23
+ label:,
24
+ value:
25
+ }
26
+ hash[:percentage] = percentage if percentage
27
+ hash
28
+ end
21
29
  end
22
30
  end
23
31
  end
@@ -16,7 +16,7 @@ module Diagrams
16
16
  #
17
17
  # @return [Hash{Symbol => String | nil}]
18
18
  def to_h
19
- # Rely on Dry::Struct's default to_h, filtering out nil label.
19
+ # Start with Dry::Struct's hash and drop nil attributes.
20
20
  super.compact
21
21
  end
22
22
  end
@@ -19,7 +19,7 @@ module Diagrams
19
19
  #
20
20
  # @return [Hash{Symbol => String | nil}]
21
21
  def to_h
22
- # Rely on Dry::Struct's default to_h, filtering out nil label.
22
+ # Start with Dry::Struct's hash and drop nil attributes.
23
23
  super.compact
24
24
  end
25
25
  end
@@ -12,8 +12,8 @@ module Diagrams
12
12
  # @param version [String, Integer, nil] User-defined version identifier.
13
13
  def initialize(entities: [], relationships: [], version: 1)
14
14
  super(version:)
15
- @entities = (entities.is_a?(Array) ? entities : []).each_with_object({}) { |e, h| h[e.name] = e }
16
- @relationships = relationships.is_a?(Array) ? relationships : []
15
+ @entities = Array(entities).each_with_object({}) { |e, h| h[e.name] = e }
16
+ @relationships = Array(relationships)
17
17
  validate_relationships!
18
18
  update_checksum!
19
19
  end
@@ -12,8 +12,8 @@ module Diagrams
12
12
  # @param version [String, Integer, nil] User-defined version identifier.
13
13
  def initialize(nodes: [], edges: [], version: 1)
14
14
  super(version:)
15
- @nodes = nodes.is_a?(Array) ? nodes : []
16
- @edges = edges.is_a?(Array) ? edges : []
15
+ @nodes = Array(nodes)
16
+ @edges = Array(edges)
17
17
  validate_elements!
18
18
  update_checksum!
19
19
  end
@@ -15,7 +15,7 @@ module Diagrams
15
15
  def initialize(title: '', sections: [], version: 1)
16
16
  super(version:)
17
17
  @title = title.is_a?(String) ? title : ''
18
- @sections = sections.is_a?(Array) ? sections : []
18
+ @sections = Array(sections)
19
19
  ensure_default_section if @sections.empty?
20
20
  validate_elements!
21
21
  update_checksum!
@@ -15,7 +15,7 @@ module Diagrams
15
15
  @title = title.is_a?(String) ? title : ''
16
16
  @slices = [] # Initialize empty
17
17
  # Add initial slices using the corrected add_slice method
18
- (slices.is_a?(Array) ? slices : []).each { |s| add_slice(s, update_checksum: false, initial_load: true) }
18
+ Array(slices).each { |s| add_slice(s, update_checksum: false, initial_load: true) }
19
19
  recalculate_percentages! # Calculate initial percentages
20
20
  update_checksum! # Calculate final checksum after initial load
21
21
  end
@@ -15,9 +15,9 @@ module Diagrams
15
15
  def initialize(title: '', states: [], transitions: [], events: [], version: 1)
16
16
  super(version:)
17
17
  @title = title.is_a?(String) ? title : ''
18
- @states = states.is_a?(Array) ? states : []
19
- @transitions = transitions.is_a?(Array) ? transitions : []
20
- @events = events.is_a?(Array) ? events : [] # Keep events for now
18
+ @states = Array(states)
19
+ @transitions = Array(transitions)
20
+ @events = Array(events) # Keep events for now
21
21
  validate_elements!
22
22
  update_checksum!
23
23
  end
@@ -15,7 +15,7 @@ module Diagrams
15
15
  def initialize(title: nil, sections: [], version: 1)
16
16
  super(version:)
17
17
  @title = title&.strip
18
- @sections = sections.is_a?(Array) ? sections : []
18
+ @sections = Array(sections)
19
19
  # Ensure there's always at least a default section if none provided initially
20
20
  ensure_default_section if @sections.empty?
21
21
  update_checksum!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Diagrams
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.4'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diagram
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: dry-equalizer
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
293
  - !ruby/object:Gem::Version
294
294
  version: '0'
295
295
  requirements: []
296
- rubygems_version: 3.6.2
296
+ rubygems_version: 3.6.7
297
297
  specification_version: 4
298
298
  summary: Work with diagrams in Ruby
299
299
  test_files: []