Module: Eco::Data::Locations::NodeBase::CsvConvert

Includes:
Parsing
Included in:
Builder
Defined in:
lib/eco/data/locations/node_base/csv_convert.rb

Instance Attribute Summary

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from Parsing

#csv_nodes_from, #hash_tree_from_csv, #nodes_from_csv

Methods included from Treeify

#treeify

Methods included from Language::AuxiliarLogger

#log

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

Instance Method Details

#csv_list(value) {|Node| ... } ⇒ CSV::Table

Note:

it just converts to an organizational tagtree and uses a helper method.

Returns a table with a list of nodes and their parents.

Parameters:

Yields:

  • (Node)

    optional custom serializer

Yield Returns:

  • (Hash)

    the serialized Node

Returns:

  • (CSV::Table)

    a table with a list of nodes and their parents



52
53
54
55
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 52

def csv_list(value, &block)
  value = org_tree(value, &block) unless value.is_a?(tree_class)
  Eco::CSV::Table.new(hash_list(value))
end

#csv_tree(value, encoding: 'utf-8', attrs: [:id]) {|Node| ... } ⇒ CSV::Table

Returns a table with L1 to Ln columns ready for dump to csv.

Yields:

  • (Node)

    optional custom serializer

Yield Returns:

  • (Hash)

    the serialized Node

Returns:

  • (CSV::Table)

    a table with L1 to Ln columns ready for dump to csv



43
44
45
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 43

def csv_tree(value, encoding: 'utf-8', attrs: [:id], &block)
  Eco::CSV::Table.new(hash_tree_to_tree_csv(hash_tree(value, &block), attrs: attrs))
end

#hash_list(value) {|Node| ... } ⇒ Array<Hash>

Returns a plain list of hash nodes.

Parameters:

Yields:

  • (Node)

    optional custom serializer

Yield Returns:

  • (Hash)

    the serialized Node

Returns:

  • (Array<Hash>)

    a plain list of hash nodes

Raises:

  • (ArgumentError)


13
14
15
16
17
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 13

def hash_list(value, &block)
  return hash_list(org_tree(value)) if value.is_a?(::CSV::Table)
  return value.as_nodes_json        if value.is_a?(tree_class)
  raise ArgumentError, "Expecting Eco::API::Organization::TagTree or CSV::Table. Given: #{value.class}"
end

#hash_tree(value) {|Node| ... } ⇒ Array<Hash>

Returns a hierarchical tree of hash nodes, ready to be parsed as an organization tagtree.

Parameters:

Yields:

  • (Node)

    optional custom serializer

Yield Returns:

  • (Hash)

    the serialized Node

Returns:

  • (Array<Hash>)

    a hierarchical tree of hash nodes, ready to be parsed as an organization tagtree

Raises:

  • (ArgumentError)


24
25
26
27
28
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 24

def hash_tree(value, &block)
  return hash_tree_from_csv(value, &block) if value.is_a?(::CSV::Table)
  return value.as_json(&block)             if value.is_a?(tree_class)
  raise ArgumentError, "Expecting Eco::API::Organization::TagTree or CSV::Table. Given: #{value.class}"
end

#org_tree(value) {|Node| ... } ⇒ Eco::API::Organization::TagTree

Parameters:

Yields:

  • (Node)

    optional custom serializer

Yield Returns:

  • (Hash)

    the serialized Node

Returns:

Raises:

  • (ArgumentError)


34
35
36
37
38
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 34

def org_tree(value, &block)
  return tree_class.new(hash_tree(value), &block) if value.is_a?(::CSV::Table)
  return tree_class.new(value.as_json)            if value.is_a?(tree_class)
  raise ArgumentError, "Expecting Eco::API::Organization::TagTree or CSV::Table. Given: #{value.class}"
end

#tree_classObject



5
6
7
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 5

def tree_class
  Eco::API::Organization::TagTree
end