Module: Eco::Data::Locations::NodeBase::Builder

Includes:
CsvConvert, Parsing, Serial, Treeify
Included in:
Eco::Data::Locations::NodeBase
Defined in:
lib/eco/data/locations/node_base/builder.rb

Instance Attribute Summary

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from Treeify

#serialize_node, #treeify

Methods included from Language::AuxiliarLogger

#log

Methods included from CsvConvert

#csv_list, #csv_tree, #hash_list, #hash_tree, #org_tree, #tree_class

Methods included from Parsing

#csv_nodes_from, #hash_tree_from_csv, #nodes_from_csv

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 Serial

#nodes_to_csv_list, #nodes_to_csv_tree, #serializer

Instance Method Details

#node_class(data) ⇒ NodeBase::Class

Returns the Node class we can use.

Parameters:

Returns:

  • (NodeBase::Class)

    the Node class we can use.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/eco/data/locations/node_base/builder.rb', line 10

def node_class(data)
  case data
  when ::CSV::Table
    return Eco::Data::Locations::NodePlain if Eco::Data::Locations::NodePlain.csv_matches_format?(csv)
    return Eco::Data::Locations::NodeLevel if Eco::Data::Locations::NodeLevel.csv_matches_format?(csv)
  when Array
    return nil unless sample = data.first
    node_class(sample)
  when Eco::Data::Locations::NodeBase
    return nil unless data.class < Eco::Data::Locations::NodeBase
    data.class
  else
    raise ArgumentError, "Expecting CSV::Table. Given: #{csv.class}" unless csv.is_a?(::CSV::Table)
  end
end