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

Extended by:
Builder
Includes:
TagValidations
Included in:
NodeLevel, NodePlain
Defined in:
lib/eco/data/locations/node_base.rb,
lib/eco/data/locations/node_base/serial.rb,
lib/eco/data/locations/node_base/builder.rb,
lib/eco/data/locations/node_base/parsing.rb,
lib/eco/data/locations/node_base/treeify.rb,
lib/eco/data/locations/node_base/csv_convert.rb,
lib/eco/data/locations/node_base/tag_validations.rb

Defined Under Namespace

Modules: Builder, CsvConvert, Parsing, Serial, TagValidations, Treeify

Constant Summary collapse

ALL_ATTRS =
[].freeze

Constants included from TagValidations

TagValidations::ALLOWED_CHARACTERS, TagValidations::DOUBLE_BLANKS, TagValidations::INVALID_TAG_REGEX, TagValidations::VALID_TAG_CHARS, TagValidations::VALID_TAG_REGEX

Instance Attribute Summary collapse

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from Builder

node_class

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

Methods included from TagValidations

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

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



15
16
17
# File 'lib/eco/data/locations/node_base.rb', line 15

def parent
  @parent
end

#tracked_levelObject

Returns the value of attribute tracked_level.



15
16
17
# File 'lib/eco/data/locations/node_base.rb', line 15

def tracked_level
  @tracked_level
end

Instance Method Details

#attr(sym) ⇒ Object



21
22
23
# File 'lib/eco/data/locations/node_base.rb', line 21

def attr(sym)
  send(sym.to_sym)
end

#attr?(sym) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/eco/data/locations/node_base.rb', line 25

def attr?(sym)
  !attr(sym).to_s.strip.empty?
end

#copyObject



17
18
19
# File 'lib/eco/data/locations/node_base.rb', line 17

def copy
  self.class.new.set_attrs(**to_h)
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



46
47
48
49
50
51
# File 'lib/eco/data/locations/node_base.rb', line 46

def node_hash(stringify_keys: true)
  json = to_h(:id, :name, :parent_id)
  json.transform_keys!(&:to_s)   if stringify_keys
  json.merge!(yield(self, json)) if block_given?
  json
end

#set_attr(attr, value) ⇒ Object



34
35
36
# File 'lib/eco/data/locations/node_base.rb', line 34

def set_attr(attr, value)
  send("#{attr}=", value)
end

#set_attrs(**kargs) ⇒ Object



29
30
31
32
# File 'lib/eco/data/locations/node_base.rb', line 29

def set_attrs(**kargs)
  kargs.each {|attr, value| set_attr(attr, value)}
  self
end

#slice(*attrs) ⇒ Object



58
59
60
61
# File 'lib/eco/data/locations/node_base.rb', line 58

def slice(*attrs)
  return {} if attrs.empty?
  to_h(*attrs)
end

#to_h(*attrs) ⇒ Object



53
54
55
56
# File 'lib/eco/data/locations/node_base.rb', line 53

def to_h(*attrs)
  attrs = self.class::ALL_ATTRS if attrs.empty?
  attrs.zip(values_at(*attrs)).to_h
end

#values_at(*attrs) ⇒ Object



38
39
40
# File 'lib/eco/data/locations/node_base.rb', line 38

def values_at(*attrs)
  attrs.map {|a| attr(a)}
end