Module: Eco::Data::Locations::NodeBase::Parsing
- Included in:
- Builder, CsvConvert
- Defined in:
- lib/eco/data/locations/node_base/parsing.rb
Instance Attribute Summary
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#csv_nodes_from(filename, encoding: 'utf-8') ⇒ Array<NodePlain>, Array<NodeLevel>
Shortcut to obtain a list of parsed nodes out of a file.
-
#hash_tree_from_csv(csv) {|node, json| ... } ⇒ Array<Hash>
A hierarchical tree of nested Hashes via
nodes
key. -
#nodes_from_csv(csv) ⇒ Array<NodePlain>, Array<NodeLevel>
With integrity issues resolved.
Methods included from Treeify
Methods included from Language::AuxiliarLogger
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
28 29 30 |
# File 'lib/eco/data/locations/node_base/parsing.rb', line 28 def csv_nodes_from(filename, encoding: 'utf-8') nodes_from_csv(csv_from(filename, encoding: encoding)) end |
#hash_tree_from_csv(csv) {|node, json| ... } ⇒ Array<Hash>
Returns a hierarchical tree of nested Hashes via nodes
key.
20 21 22 23 |
# File 'lib/eco/data/locations/node_base/parsing.rb', line 20 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.
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 |