Sha256: 40aa1db2482dee9c71f23165537088ac517fe20bd93c50f977ca61de2015d2d4

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

module Eco::Data::Locations
  module NodeBase
    require_relative 'node_base/tag_validations'
    include Eco::Data::Locations::NodeBase::TagValidations

    require_relative 'node_base/treeify'
    require_relative 'node_base/parsing'
    require_relative 'node_base/serial'
    require_relative 'node_base/csv_convert'
    require_relative 'node_base/builder'
    extend Eco::Data::Locations::NodeBase::Builder

    ALL_ATTRS = []

    attr_accessor :tracked_level, :parent

    def copy
      self.class.new.set_attrs(**self.to_h)
    end

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

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

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

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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
eco-helpers-2.5.8 lib/eco/data/locations/node_base.rb
eco-helpers-2.5.7 lib/eco/data/locations/node_base.rb
eco-helpers-2.5.6 lib/eco/data/locations/node_base.rb
eco-helpers-2.5.5 lib/eco/data/locations/node_base.rb
eco-helpers-2.5.4 lib/eco/data/locations/node_base.rb
eco-helpers-2.5.3 lib/eco/data/locations/node_base.rb