Module: Eco::Data::Locations::NodeBase::CsvConvert
Instance Attribute Summary
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
-
#csv_list(value) {|node, json| ... } ⇒ CSV::Table
A table with a list of nodes and their parents.
-
#csv_tree(value, encoding: 'utf-8', attrs: [:id]) {|node, json| ... } ⇒ CSV::Table
A table with L1 to Ln columns ready for dump to csv.
-
#hash_list(value) {|node, json| ... } ⇒ Array<Hash>
A plain list of hash nodes.
-
#hash_tree(value) {|node, json| ... } ⇒ Array<Hash>
A hierarchical tree of hash nodes, ready to be parsed as an organization tagtree.
- #org_tree(value) {|node, json| ... } ⇒ 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, json| ... } ⇒ 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.
62 63 64 65 |
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 62 def csv_list(value, &block) value = org_tree(value, &block) unless value.is_a?(tree_class) Eco::CSV::Table.new(hash_list(value, &block)) end |
#csv_tree(value, encoding: 'utf-8', attrs: [:id]) {|node, json| ... } ⇒ CSV::Table
Returns a table with L1 to Ln columns ready for dump to csv.
51 52 53 |
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 51 def csv_tree(value, encoding: 'utf-8', attrs: [:id], &block) # rubocop:disable Lint/UnusedMethodArgument Eco::CSV::Table.new(hash_tree_to_tree_csv(hash_tree(value, &block), attrs: attrs)) end |
#hash_list(value) {|node, json| ... } ⇒ Array<Hash>
Returns a plain list of hash nodes.
15 16 17 18 19 |
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 15 def hash_list(value, &block) return hash_list(org_tree(value), &block) if value.is_a?(::CSV::Table) return value.as_nodes_json(&block) if value.is_a?(tree_class) raise ArgumentError, "Expecting Eco::API::Organization::TagTree or CSV::Table. Given: #{value.class}" end |
#hash_tree(value) {|node, json| ... } ⇒ Array<Hash>
Returns a hierarchical tree of hash nodes, ready to be parsed as an organization tagtree.
28 29 30 31 32 |
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 28 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, json| ... } ⇒ Eco::API::Organization::TagTree
40 41 42 43 44 |
# File 'lib/eco/data/locations/node_base/csv_convert.rb', line 40 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 |