Class: Eco::Data::Locations::NodeLevel
- Inherits:
-
NodeLevelStruct
show all
- Extended by:
- Builder
- Includes:
- NodeBase
- Defined in:
- lib/eco/data/locations/node_level.rb,
lib/eco/data/locations/node_level/serial.rb,
lib/eco/data/locations/node_level/builder.rb,
lib/eco/data/locations/node_level/cleaner.rb,
lib/eco/data/locations/node_level/parsing.rb
Overview
Class to treat input csv in a form of levels, where each column is one level,
and children are placed in higher columns right below the parent.
Defined Under Namespace
Modules: Builder, Cleaner, Parsing, Serial
Constant Summary
collapse
- ALL_ATTRS =
NODE_LEVEL_ATTRS
- ADDITIONAL_ATTRS =
%i[row_num]
- TAGS_ATTRS =
ALL_ATTRS - ADDITIONAL_ATTRS
Eco::Data::Locations::NodeBase::TagValidations::ALLOWED_CHARACTERS, Eco::Data::Locations::NodeBase::TagValidations::DOUBLE_BLANKS, Eco::Data::Locations::NodeBase::TagValidations::INVALID_TAG_REGEX, Eco::Data::Locations::NodeBase::TagValidations::VALID_TAG_CHARS, Eco::Data::Locations::NodeBase::TagValidations::VALID_TAG_REGEX
Instance Attribute Summary collapse
Attributes included from Serial
#serializer
#logger
Attributes included from Parsing
#node_class
Attributes included from NodeBase
#parent, #tracked_level
Instance Method Summary
collapse
Methods included from Serial
#nodes_to_csv_tree
Methods included from Convert
#csv_from, #empty_array, #empty_level_tracker_hash, #hash_tree_to_tree_csv, #log_pretty_inspect, #normalize_arrays, #report_repeated_node_ids
#log
Methods included from Cleaner
#done_ids, #fill_in_parents, #repeated_ids, #reset_trackers!, #tidy_nodes
Methods included from Parsing
#csv_matches_format?, #nodes_from_csv
Methods included from NodeBase
#attr, #copy, #set_attr, #set_attrs, #slice, #to_h, #values_at
#node_class
#treeify
#csv_list, #csv_tree, #hash_list, #hash_tree, #org_tree, #tree_class
#csv_nodes_from, #hash_tree_from_csv, #nodes_from_csv
#nodes_to_csv_list, #nodes_to_csv_tree, #serializer
#clean_id, #has_double_blanks?, #identify_invalid_characters, #invalid_warned!, #invalid_warned?, #remove_double_blanks, #replace_not_allowed
Instance Attribute Details
#parentId ⇒ Object
Returns the value of attribute parentId.
19
20
21
|
# File 'lib/eco/data/locations/node_level.rb', line 19
def parentId
@parentId
end
|
Instance Method Details
#actual_level ⇒ Object
45
46
47
|
# File 'lib/eco/data/locations/node_level.rb', line 45
def actual_level
tags_array.compact.length
end
|
#blanks_between? ⇒ Boolean
144
145
146
|
# File 'lib/eco/data/locations/node_level.rb', line 144
def blanks_between?
actual_level > empty_idx
end
|
#clear_level(i) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/eco/data/locations/node_level.rb', line 94
def clear_level(i)
case i
when Enumerable
target = i.to_a
when Integer
return false unless i >= 1 && i <= tag_attrs_count
target = Array(i..tag_attrs_count)
else
return false
end
return false if target.empty?
target.each do |n|
set_attr("l#{n}", nil)
end
true
end
|
#decouple(num = 1) ⇒ Object
We got a missing level that is compacted in one row
Here we get the missing intermediate levels
This is done from upper to lower level to ensure processing order
It skips last one, as that is this object already
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/eco/data/locations/node_level.rb', line 71
def decouple(num = 1)
with_info = filled_idxs
unless with_info.last == tag_idx
raise "Review this (row #{row_num}; '#{raw_tag}'): tag_idx is #{tag_idx}, while last filled idx is #{with_info.last}"
end
len = with_info.length
target_idxs = with_info[len-(num+1)..-2]
target_idxs.map do |idx|
self.copy.tap do |dup|
dup.clear_level(idx_to_level(idx + 1))
end
end
end
|
#empty_idx ⇒ Object
62
63
64
65
|
# File 'lib/eco/data/locations/node_level.rb', line 62
def empty_idx
tary = tags_array
tary.index(nil) || tary.length + 1
end
|
#filled_idxs ⇒ Object
138
139
140
141
142
|
# File 'lib/eco/data/locations/node_level.rb', line 138
def filled_idxs
tags_array.each_with_index.with_object([]) do |(tg, ix), out|
out << ix if tg
end
end
|
#id ⇒ Object
25
26
27
|
# File 'lib/eco/data/locations/node_level.rb', line 25
def id
tag.upcase
end
|
#idx_to_level(x) ⇒ Object
130
131
132
|
# File 'lib/eco/data/locations/node_level.rb', line 130
def idx_to_level(x)
x + 1
end
|
#level ⇒ Object
41
42
43
|
# File 'lib/eco/data/locations/node_level.rb', line 41
def level
actual_level
end
|
#level_to_idx(x) ⇒ Object
134
135
136
|
# File 'lib/eco/data/locations/node_level.rb', line 134
def level_to_idx(x)
x - 1
end
|
#merge!(node) ⇒ Object
86
87
88
|
# File 'lib/eco/data/locations/node_level.rb', line 86
def merge!(node)
override_upper_levels(node.tags_array)
end
|
#name ⇒ Object
29
30
31
|
# File 'lib/eco/data/locations/node_level.rb', line 29
def name
tag
end
|
#nodeId ⇒ Object
21
22
23
|
# File 'lib/eco/data/locations/node_level.rb', line 21
def nodeId
id
end
|
#override_lower_levels(src_tags_array, to_level: self.raw_level - 1) ⇒ Object
121
122
123
124
125
126
127
128
|
# File 'lib/eco/data/locations/node_level.rb', line 121
def override_lower_levels(src_tags_array, to_level: self.raw_level - 1)
target_lev = Array(1..to_level)
target_tags = src_tags_array[level_to_idx(1)..level_to_idx(to_level)]
target_lev.zip(target_tags).each do |(n, tag)|
set_attr("l#{n}", tag)
end
self
end
|
#override_upper_levels(src_tags_array, from_level: self.raw_level + 1) ⇒ Object
112
113
114
115
116
117
118
119
|
# File 'lib/eco/data/locations/node_level.rb', line 112
def override_upper_levels(src_tags_array, from_level: self.raw_level + 1)
target_lev = Array(from_level..tag_attrs_count)
target_tags = src_tags_array[level_to_idx(from_level)..level_to_idx(tag_attrs_count)]
target_lev.zip(target_tags).each do |(n, tag)|
set_attr("l#{n}", tag)
end
self
end
|
#previous_idx ⇒ Object
57
58
59
60
|
# File 'lib/eco/data/locations/node_level.rb', line 57
def previous_idx
idx = tag_idx - 1
idx < 0 ? nil : idx
end
|
#raw_level ⇒ Object
49
50
51
|
# File 'lib/eco/data/locations/node_level.rb', line 49
def raw_level
tags_array.index(raw_tag) + 1
end
|
#raw_tag ⇒ Object
37
38
39
|
# File 'lib/eco/data/locations/node_level.rb', line 37
def raw_tag
values_at(*TAGS_ATTRS.reverse).compact.first
end
|
#set_high_levels(node) ⇒ Object
90
91
92
|
# File 'lib/eco/data/locations/node_level.rb', line 90
def set_high_levels(node)
override_lower_levels(node.tags_array)
end
|
#tag ⇒ Object
33
34
35
|
# File 'lib/eco/data/locations/node_level.rb', line 33
def tag
clean_id(raw_tag)
end
|
#tag_attrs_count ⇒ Object
152
153
154
|
# File 'lib/eco/data/locations/node_level.rb', line 152
def tag_attrs_count
TAGS_ATTRS.length
end
|
#tag_idx ⇒ Object
53
54
55
|
# File 'lib/eco/data/locations/node_level.rb', line 53
def tag_idx
tags_array.index(raw_tag)
end
|
148
149
150
|
# File 'lib/eco/data/locations/node_level.rb', line 148
def tags_array
values_at(*TAGS_ATTRS)
end
|