Sha256: 61d8eb799ce1c3732130da853fef9ac66f60da318b8d244602237570254182d1

Contents?: true

Size: 1.87 KB

Versions: 13

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

require_relative "pathname_utility"
module JsDependency
  class TargetPathname
    attr_accessor :color_css, :font_size_css

    # @param [String] target_path
    def initialize(target_path)
      @pathname = to_target_pathname(target_path)
    end

    # @param [Integer] analyze_level
    # @param [Hash] index
    def each_parent_path(analyze_level, index)
      temp_paths = [@pathname.to_s]
      analyze_level.times do
        list = []
        temp_paths.each do |temp_path|
          temp_pathname = to_target_pathname(temp_path)

          list += extract_parent_paths(temp_pathname.to_s, index).each do |parent_path|
            yield parent_path, temp_pathname.to_s
          end
        end
        temp_paths = list
      end
    end

    # @param [Integer] analyze_level
    # @param [Hash] index
    def each_child_path(analyze_level, index)
      temp_paths = [@pathname.to_s]
      analyze_level.times do
        list = []
        temp_paths.each do |temp_path|
          temp_pathname = to_target_pathname(temp_path)

          list += extract_children_paths(temp_pathname.to_s, index).each do |child_path|
            yield temp_pathname.to_s, child_path
          end
        end
        temp_paths = list
      end
    end

    private

    # @param [String] target_path
    # @param [Hash] index
    # @return [Array]
    def extract_parent_paths(target_path, index)
      index.each_with_object([]) do |(parent, children), list|
        list << parent if children.any?(target_path)
      end
    end

    # @param [String] target_path
    # @param [Hash] index
    # @return [Array]
    def extract_children_paths(target_path, index)
      index[target_path] || []
    end

    # @param [String] target_path
    # @return [Pathname]
    def to_target_pathname(target_path)
      JsDependency::PathnameUtility.to_target_pathname(target_path)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
js_dependency-0.4.1 lib/js_dependency/target_pathname.rb
js_dependency-0.4.0 lib/js_dependency/target_pathname.rb
js_dependency-0.3.15 lib/js_dependency/target_pathname.rb
js_dependency-0.3.14 lib/js_dependency/target_pathname.rb
js_dependency-0.3.13 lib/js_dependency/target_pathname.rb
js_dependency-0.3.12 lib/js_dependency/target_pathname.rb
js_dependency-0.3.11 lib/js_dependency/target_pathname.rb
js_dependency-0.3.10 lib/js_dependency/target_pathname.rb
js_dependency-0.3.9 lib/js_dependency/target_pathname.rb
js_dependency-0.3.8 lib/js_dependency/target_pathname.rb
js_dependency-0.3.7 lib/js_dependency/target_pathname.rb
js_dependency-0.3.6 lib/js_dependency/target_pathname.rb
js_dependency-0.3.5 lib/js_dependency/target_pathname.rb