Module: Eco::Data::Locations::NodeLevel::Serial
- Included in:
- Builder
- Defined in:
- lib/eco/data/locations/node_level/serial.rb
Instance Attribute Summary collapse
-
#serializer ⇒ Proc
The serializer to be used.
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#nodes_to_csv_tree(nodes) ⇒ CSV::Table
Transforms
nodes
into a hierarchical 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
Methods included from Language::AuxiliarLogger
Methods included from Cleaner
#done_ids, #fill_in_parents, #repeated_ids, #reset_trackers!, #tidy_nodes
Instance Attribute Details
#serializer ⇒ Proc
Returns the serializer to be used.
9 10 11 12 13 14 15 16 17 |
# File 'lib/eco/data/locations/node_level/serial.rb', line 9 def serializer @serializer ||= proc do |node| raise "Expecting NodeLevel. Given: #{node.class}" unless node.is_a?(Eco::Data::Locations::NodeLevel) keys = %w[row_num id name] keys.zip(node.values_at(*keys)).to_h.tap do |out| out['parent_id'] = node.parentId end end end |
Instance Method Details
#nodes_to_csv_tree(nodes) ⇒ CSV::Table
Note:
tidy_nodes
is called out of consistency. For example, it might be that the parents are not set. After this call, all the integrity issues have been warned.NodeBase
has this same class method. This one was kept to preserve its indepenence towards treeify.
Transforms nodes
into a hierarchical csv tree.
27 28 29 30 31 32 33 34 35 |
# File 'lib/eco/data/locations/node_level/serial.rb', line 27 def nodes_to_csv_tree(nodes) tidy_nodes(nodes).each_with_object([]) do |node, out| out << (row = empty_array(node.actual_level)) # replace last item with `node.id` row[-1..-1] = [node.id] end.tap do |out| return Eco::CSV::Table.new(normalize_arrays(out)) end end |