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
TagValidations::ALLOWED_CHARACTERS, TagValidations::DOUBLE_BLANKS, TagValidations::INVALID_TAG_REGEX, TagValidations::VALID_TAG_CHARS, TagValidations::VALID_TAG_REGEX
Instance Attribute Summary collapse
#logger
Instance Method Summary
collapse
Methods included from Builder
node_class
Methods included from Treeify
#serialize_node, #treeify
#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
#clean_id, #has_double_blanks?, #identify_invalid_characters, #invalid_warned, #invalid_warned!, #invalid_warned?, #remove_double_blanks, #replace_not_allowed
Instance Attribute Details
Returns the value of attribute parent.
15
16
17
|
# File 'lib/eco/data/locations/node_base.rb', line 15
def parent
@parent
end
|
#tracked_level ⇒ Object
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
25
26
27
|
# File 'lib/eco/data/locations/node_base.rb', line 25
def attr(sym)
send(sym.to_sym)
end
|
#attr?(sym) ⇒ Boolean
29
30
31
|
# File 'lib/eco/data/locations/node_base.rb', line 29
def attr?(sym)
!attr(sym).to_s.strip.empty? end
|
21
22
23
|
# File 'lib/eco/data/locations/node_base.rb', line 21
def copy
self.class.new.set_attrs(**to_h)
end
|
#node_hash(stringify_keys: true) {|node, json| ... } ⇒ Object
50
51
52
53
54
55
|
# File 'lib/eco/data/locations/node_base.rb', line 50
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
|
#self_parented? ⇒ Boolean
17
18
19
|
# File 'lib/eco/data/locations/node_base.rb', line 17
def self_parented?
raise 'You should implement this method in child classes'
end
|
#set_attr(attr, value) ⇒ Object
38
39
40
|
# File 'lib/eco/data/locations/node_base.rb', line 38
def set_attr(attr, value)
send("#{attr}=", value)
end
|
#set_attrs(**kargs) ⇒ Object
33
34
35
36
|
# File 'lib/eco/data/locations/node_base.rb', line 33
def set_attrs(**kargs)
kargs.each {|attr, value| set_attr(attr, value)}
self
end
|
#slice(*attrs) ⇒ Object
62
63
64
65
66
|
# File 'lib/eco/data/locations/node_base.rb', line 62
def slice(*attrs)
return {} if attrs.empty?
to_h(*attrs)
end
|
#to_h(*attrs) ⇒ Object
57
58
59
60
|
# File 'lib/eco/data/locations/node_base.rb', line 57
def to_h(*attrs)
attrs = self.class::ALL_ATTRS if attrs.empty?
attrs.zip(values_at(*attrs)).to_h
end
|
#values_at(*attrs) ⇒ Object
42
43
44
|
# File 'lib/eco/data/locations/node_base.rb', line 42
def values_at(*attrs)
attrs.map {|a| attr(a)}
end
|