Sha256: 24c81544bb5c033267b4e9f001d89ffde003e51a072b51e63e142e31104f5724

Contents?: true

Size: 734 Bytes

Versions: 7

Compression:

Stored size: 734 Bytes

Contents

# frozen_string_literal: true

module JsDependency
  module Mermaid
    class NodesLink
      attr_reader :parent, :child

      def initialize(parent, child)
        @parent = parent
        @child = child
      end

      def parent_module_name(level = 0)
        parse(Pathname.new(@parent), level).join("/")
      end

      def child_module_name(level = 0)
        parse(Pathname.new(@child), level).join("/")
      end

      private

      def parse(pathname, level)
        return [pathname.to_s] unless pathname.exist?

        array = [pathname.basename]
        level.times do
          array.unshift(pathname.parent.basename.to_s)
          pathname = pathname.parent
        end
        array
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
js_dependency-0.2.3.1 lib/js_dependency/mermaid/nodes_link.rb
js_dependency-0.2.3 lib/js_dependency/mermaid/nodes_link.rb
js_dependency-0.2.2 lib/js_dependency/mermaid/nodes_link.rb
js_dependency-0.2.1 lib/js_dependency/mermaid/nodes_link.rb
js_dependency-0.2.0 lib/js_dependency/mermaid/nodes_link.rb
js_dependency-0.1.1 lib/js_dependency/mermaid/nodes_link.rb
js_dependency-0.1.0 lib/js_dependency/mermaid/nodes_link.rb