eco-helpers 3.2.6 → 3.2.7

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: 8bb545e3154c1a65a993a24b6eeab4eebbe125e95492bc2b6961fee0a708a80f
4
- data.tar.gz: dc6bd380cd757b5218fadf264c64ef8a61b767916514aebac63fae0739c5153c
3
+ metadata.gz: bfe97cd5583e8650f73c0f7cb2557fde896d3b59b7e729703fdb01f9323d6fbb
4
+ data.tar.gz: e40c8fdeae21780ca957c043aa7a637d06d9e85088fdbca6eb7c488448c74ab5
5
5
  SHA512:
6
- metadata.gz: b9852caf3f9f2dcdcbcbe4d17e325c566e63b3724b92349668e35fb4839aea5b7879b3b080b031868495b40c5bb09a9fc9d43c0b5cd4e9dbc298ec0f25d867d8
7
- data.tar.gz: 5941ec298de1bff8205be578bcefaed0602dfea76ceee47a00497b28ff973a293553927d1ce96f0617abe0886c5fa4f5810678e69c3fab2673fd35c6df88dac3
6
+ metadata.gz: c1f28e77164e7f8c439b09dba5d952594c34721457842963cfb9e037c90658de8049545c1029e25e6aa2aadda2a729a4fc103fb04335adcfb6359b1fe946ad60
7
+ data.tar.gz: '090c4c12745401c0191aec263bb3970bd92e5244c6b57f4d5ef6dd157acab37ab868ed239972d133bd52a4eb11ddcac0e4857a8e760e10321b7236f50a7d3c76'
data/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [3.2.7] - 2025-09-xx
5
+ ## [3.2.8] - 2025-09-xx
6
6
 
7
7
  ### Added
8
8
 
@@ -10,6 +10,16 @@ All notable changes to this project will be documented in this file.
10
10
 
11
11
  ### Fixed
12
12
 
13
+ ## [3.2.7] - 2025-09-09
14
+
15
+ ### Added
16
+
17
+ - `NodeBase` (and subclasses): **added** missed case `#self_parented?`
18
+
19
+ ### Fixed
20
+
21
+ - **Added** early detection of `self-parented` nodes (from the input file).
22
+
13
23
  ## [3.2.6] - 2025-09-05
14
24
 
15
25
  ### Added
@@ -24,14 +34,6 @@ All notable changes to this project will be documented in this file.
24
34
  - This was a working around due to not using `as_nodes_json` as a **common** converter between `live_tree` and `file_tree` (which was fixed in a previous release).
25
35
  - `as_nodes_json` already does the call to `node_parser_block`, which does the conversion of the **classifications**
26
36
 
27
- ## [3.2.6] - 2025-09-xx
28
-
29
- ### Added
30
-
31
- ### Changed
32
-
33
- ### Fixed
34
-
35
37
  ## [3.2.5] - 2025-09-04
36
38
 
37
39
  ### Changed
@@ -11,15 +11,19 @@ module Eco::Data::Locations::NodeBase
11
11
  case data
12
12
  when ::CSV::Table
13
13
  return Eco::Data::Locations::NodePlain if Eco::Data::Locations::NodePlain.csv_matches_format?(csv)
14
- return Eco::Data::Locations::NodeLevel if Eco::Data::Locations::NodeLevel.csv_matches_format?(csv)
14
+
15
+ Eco::Data::Locations::NodeLevel if Eco::Data::Locations::NodeLevel.csv_matches_format?(csv)
15
16
  when Array
16
- return nil unless sample = data.first
17
+ return unless (sample = data.first)
18
+
17
19
  node_class(sample)
18
20
  when Eco::Data::Locations::NodeBase
19
- return nil unless data.class < Eco::Data::Locations::NodeBase
21
+ return unless data.class < Eco::Data::Locations::NodeBase
22
+
20
23
  data.class
21
24
  else
22
- raise ArgumentError, "Expecting CSV::Table. Given: #{csv.class}" unless csv.is_a?(::CSV::Table)
25
+ msg ="Expecting CSV::Table. Given: #{csv.class}"
26
+ raise ArgumentError, msg unless csv.is_a?(::CSV::Table)
23
27
  end
24
28
  end
25
29
  end
@@ -6,10 +6,19 @@ module Eco::Data::Locations::NodeBase
6
6
  # @param csv [CSV::Table]
7
7
  # @return [Array<NodePlain>, Array<NodeLevel>] with integrity issues resolved.
8
8
  def nodes_from_csv(csv)
9
- raise ArgumentError, "Expecting CSV::Table. Given: #{csv.class}" unless csv.is_a?(::CSV::Table)
10
- return Eco::Data::Locations::NodePlain.nodes_from_csv(csv) if Eco::Data::Locations::NodePlain.csv_matches_format?(csv)
11
- return Eco::Data::Locations::NodeLevel.nodes_from_csv(csv) if Eco::Data::Locations::NodeLevel.csv_matches_format?(csv)
12
- raise ArgumentError, "The input csv does not have the required format to read a locations structure."
9
+ msg = "Expecting CSV::Table. Given: #{csv.class}"
10
+ raise ArgumentError, msg unless csv.is_a?(::CSV::Table)
11
+
12
+ if Eco::Data::Locations::NodePlain.csv_matches_format?(csv)
13
+ return Eco::Data::Locations::NodePlain.nodes_from_csv(csv)
14
+ end
15
+
16
+ if Eco::Data::Locations::NodeLevel.csv_matches_format?(csv)
17
+ return Eco::Data::Locations::NodeLevel.nodes_from_csv(csv)
18
+ end
19
+
20
+ msg = "The input csv does not have the required format to read a locations structure."
21
+ raise ArgumentError, msg
13
22
  end
14
23
 
15
24
  # @yield [node, json] optional custom serializer
@@ -18,7 +27,9 @@ module Eco::Data::Locations::NodeBase
18
27
  # @yieldreturn [Hash] the serialized Node
19
28
  # @return [Array<Hash>] a hierarchical tree of nested Hashes via `nodes` key.
20
29
  def hash_tree_from_csv(csv, &block)
21
- raise ArgumentError, "Expecting CSV::Table. Given: #{csv.class}" unless csv.is_a?(::CSV::Table)
30
+ msg = "Expecting CSV::Table. Given: #{csv.class}"
31
+ raise ArgumentError, msg unless csv.is_a?(::CSV::Table)
32
+
22
33
  treeify(nodes_from_csv(csv), &block)
23
34
  end
24
35
 
@@ -55,8 +55,25 @@ module Eco::Data::Locations::NodeBase
55
55
  # @return [Hash] where `key`s are all the `parentId` of the nodes
56
56
  # and `value` and `Array` of those nodes that have that `parentId`
57
57
  def parents_hash(nodes)
58
+ self_parented = []
59
+
58
60
  nodes.each_with_object({}) do |node, parents|
61
+ next self_parented.push(node) if node.self_parented?
62
+
59
63
  (parents[node.parentId] ||= []).push(node)
64
+ end.tap do
65
+ next if self_parented.empty?
66
+
67
+ log(:error) {
68
+ msg = "#{self_parented.count} nodes are self-parented: "
69
+ msg << self_parented.map(&:id).map do |node_id|
70
+ "'#{node_id}'"
71
+ end.join(', ')
72
+ msg << "\nPlease amend the data."
73
+ msg
74
+ }
75
+
76
+ exit 1
60
77
  end
61
78
  end
62
79
 
@@ -138,7 +155,6 @@ module Eco::Data::Locations::NodeBase
138
155
  # skipped keys is inherent, as they were excluded because of id clash with done_ids
139
156
  unlinked_parent_ids = (parents.keys - done_ids.keys).compact
140
157
 
141
-
142
158
  # The reason of missing nodes in the output tree is unknown!
143
159
  if skipped.empty? && unlinked_parent_ids.empty?
144
160
  msg = []
@@ -14,6 +14,10 @@ module Eco::Data::Locations
14
14
 
15
15
  attr_accessor :tracked_level, :parent
16
16
 
17
+ def self_parented?
18
+ raise 'You should implement this method in child classes'
19
+ end
20
+
17
21
  def copy
18
22
  self.class.new.set_attrs(**to_h)
19
23
  end
@@ -50,6 +50,10 @@ module Eco::Data::Locations
50
50
  alias_method :node_id, :id
51
51
  alias_method :nodeId, :id # rubocop:disable Naming/MethodName
52
52
 
53
+ def self_parented?
54
+ id == parent_id
55
+ end
56
+
53
57
  def name
54
58
  tag
55
59
  end
@@ -30,10 +30,6 @@ module Eco::Data::Locations
30
30
  # backwards compatibility
31
31
  alias_method :tag, :id
32
32
 
33
- def name
34
- super || id
35
- end
36
-
37
33
  def parent_id
38
34
  clean_id(
39
35
  super,
@@ -43,6 +39,14 @@ module Eco::Data::Locations
43
39
  end
44
40
  alias_method :parentId, :parent_id # rubocop:disable Naming/MethodName
45
41
 
42
+ def self_parented?
43
+ id == parent_id
44
+ end
45
+
46
+ def name
47
+ super || id
48
+ end
49
+
46
50
  def archived
47
51
  value = super
48
52
  return false if value.nil? || value == false
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = '3.2.6'.freeze
2
+ VERSION = '3.2.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.6
4
+ version: 3.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-05 00:00:00.000000000 Z
11
+ date: 2025-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug