Class: Eco::Data::Locations::NodePlain

Inherits:
NodePlainStruct show all
Extended by:
Builder
Includes:
NodeBase
Defined in:
lib/eco/data/locations/node_plain.rb,
lib/eco/data/locations/node_plain/serial.rb,
lib/eco/data/locations/node_plain/builder.rb,
lib/eco/data/locations/node_plain/parsing.rb

Overview

Class to treat input csv in a form of a list of nodes, where parent is specified.

Defined Under Namespace

Modules: Builder, Parsing, Serial

Constant Summary collapse

ALL_ATTRS =
NODE_PLAIN_ATTRS
ADDITIONAL_ATTRS =
%i[row_num].freeze
PROP_ATTRS =
(ALL_ATTRS - ADDITIONAL_ATTRS).freeze

Constants included from Eco::Data::Locations::NodeBase::TagValidations

Eco::Data::Locations::NodeBase::TagValidations::ALLOWED_CHARACTERS, Eco::Data::Locations::NodeBase::TagValidations::DOUBLE_BLANKS, Eco::Data::Locations::NodeBase::TagValidations::INVALID_TAG_REGEX, Eco::Data::Locations::NodeBase::TagValidations::VALID_TAG_CHARS, Eco::Data::Locations::NodeBase::TagValidations::VALID_TAG_REGEX

Instance Attribute Summary

Attributes included from Serial

#serializer

Attributes included from Parsing

#node_class

Attributes included from NodeBase

#parent, #tracked_level

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from Parsing

#basic_headers, #csv_matches_format?, #nodes_from_csv

Methods included from NodeBase

#attr, #attr?, #copy, #set_attr, #set_attrs, #slice, #to_h, #values_at

Methods included from Eco::Data::Locations::NodeBase::Builder

#node_class

Methods included from Eco::Data::Locations::NodeBase::Treeify

#serialize_node, #treeify

Methods included from Language::AuxiliarLogger

#log

Methods included from Eco::Data::Locations::NodeBase::CsvConvert

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

Methods included from Eco::Data::Locations::NodeBase::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 Eco::Data::Locations::NodeBase::Serial

#nodes_to_csv_list, #nodes_to_csv_tree, #serializer

Methods included from Eco::Data::Locations::NodeBase::TagValidations

#clean_id, #has_double_blanks?, #identify_invalid_characters, #invalid_warned, #invalid_warned!, #invalid_warned?, #remove_double_blanks, #replace_not_allowed

Instance Method Details

#archivedObject



50
51
52
53
54
55
56
57
58
# File 'lib/eco/data/locations/node_plain.rb', line 50

def archived
  value = super
  return false if value.nil? || value == false
  return true  if value == true
  return false if value.to_s.strip.empty?
  return true  if %w[yes x true].include?(value.downcase)

  false
end

#classification_namesObject



64
65
66
# File 'lib/eco/data/locations/node_plain.rb', line 64

def classification_names
  into_a(super)
end

#classificationsObject



60
61
62
# File 'lib/eco/data/locations/node_plain.rb', line 60

def classifications
  into_a(super)
end

#idObject Also known as: tag



24
25
26
27
28
29
# File 'lib/eco/data/locations/node_plain.rb', line 24

def id
  clean_id(
    super,
    ref: "(Row: #{row_num}) "
  )&.upcase
end

#nameObject



46
47
48
# File 'lib/eco/data/locations/node_plain.rb', line 46

def name
  super || id
end

#node_hash(stringify_keys: true) {|node, json| ... } ⇒ Object

Yields:

  • (node, json)

    optional custom serializer

Yield Parameters:

  • node (Node)

    self

  • json (Hash)

    the default serialization

Yield Returns:

  • (Hash)

    the serialized Node



72
73
74
75
76
77
# File 'lib/eco/data/locations/node_plain.rb', line 72

def node_hash(stringify_keys: true)
  json = to_h.reject {|key, _v| key == :row_num}
  json.transform_keys!(&:to_s)   if stringify_keys
  json.merge!(yield(self, json)) if block_given?
  json
end

#parent_idObject Also known as: parentId



33
34
35
36
37
38
39
# File 'lib/eco/data/locations/node_plain.rb', line 33

def parent_id
  clean_id(
    super,
    notify: false,
    ref:    "(Row: #{row_num} - parent_id) "
  )&.upcase
end

#self_parented?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/eco/data/locations/node_plain.rb', line 42

def self_parented?
  id == parent_id
end