Module: Eco::Data::Locations::NodeBase::Parsing

Includes:
Convert, Treeify
Included in:
Builder, CsvConvert
Defined in:
lib/eco/data/locations/node_base/parsing.rb

Instance Attribute Summary

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

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_nodes_from(filename, encoding: 'utf-8') ⇒ Array<NodePlain>, Array<NodeLevel>

Shortcut to obtain a list of parsed nodes out of a file

Parameters:

  • filename (String)

    the csv file.

Returns:



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

def csv_nodes_from(filename, encoding: 'utf-8')
  nodes_from_csv(csv_from(filename, encoding: 'utf-8'))
end

#hash_tree_from_csv(csv) {|Node| ... } ⇒ Array<Hash>

Returns a hierarchical tree of nested Hashes via nodes key.

Yields:

  • (Node)

    optional custom serializer

Yield Returns:

  • (Hash)

    the serialized Node

Returns:

  • (Array<Hash>)

    a hierarchical tree of nested Hashes via nodes key.

Raises:

  • (ArgumentError)


18
19
20
21
# File 'lib/eco/data/locations/node_base/parsing.rb', line 18

def hash_tree_from_csv(csv, &block)
  raise ArgumentError, "Expecting CSV::Table. Given: #{csv.class}" unless csv.is_a?(::CSV::Table)
  treeify(nodes_from_csv(csv), &block)
end

#nodes_from_csv(csv) ⇒ Array<NodePlain>, Array<NodeLevel>

Returns with integrity issues resolved.

Parameters:

Returns:

Raises:

  • (ArgumentError)


8
9
10
11
12
13
# File 'lib/eco/data/locations/node_base/parsing.rb', line 8

def nodes_from_csv(csv)
  raise ArgumentError, "Expecting CSV::Table. Given: #{csv.class}" unless csv.is_a?(::CSV::Table)
  return Eco::Data::Locations::NodePlain.nodes_from_csv(csv) if Eco::Data::Locations::NodePlain.csv_matches_format?(csv)
  return Eco::Data::Locations::NodeLevel.nodes_from_csv(csv) if Eco::Data::Locations::NodeLevel.csv_matches_format?(csv)
  raise ArgumentError, "The input csv does not have the required format to read a locations structure."
end