Module: Eco::Data::Locations::NodeBase::CsvConvert
Instance Attribute Summary
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#csv_list(value) {|Node| ... } ⇒ CSV::Table
A table with a list of nodes and their parents.
-
#csv_tree(value, encoding: 'utf-8', attrs: [:id]) {|Node| ... } ⇒ CSV::Table
A table with L1 to Ln columns ready for dump to csv.
-
#hash_list(value) {|Node| ... } ⇒ Array<Hash>
A plain list of hash nodes.
-
#hash_tree(value) {|Node| ... } ⇒ Array<Hash>
A hierarchical tree of hash nodes, ready to be parsed as an organization tagtree.
- #org_tree(value) {|Node| ... } ⇒ Eco::API::Organization::TagTree
- #tree_class ⇒ Object
Methods included from Parsing
#csv_nodes_from, #hash_tree_from_csv, #nodes_from_csv
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_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.
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.
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.
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.
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
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_class ⇒ Object
5 6 7 |
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 5 def tree_class Eco::API::Organization::TagTree end |