Sha256: be7d7586c5594f10b41e1e4597386ea3ee9aad2067a0c83ab222807b4eee0a55

Contents?: true

Size: 1004 Bytes

Versions: 18

Compression:

Stored size: 1004 Bytes

Contents

# frozen_string_literal: true

module KepplerFrontend
  module Utils
    # CodeHandler
    class CodeSearch
      def initialize(html_lines)
        @html_lines = html_lines
      end

      def search_section(point_one, point_two)
        idx = [0, 0]
        idx = begin_index(point_one, idx)
        end_index(point_two, idx)
      end

      def search_line(point)
        idx = [0]
        idx = begin_index(point, idx)
        idx.first
      end

      private

      def begin_index(point_one, idx)
        @html_lines.each do |line|
          idx[0] = @html_lines.find_index(line) if line.include?(point_one)
        end
        idx
      end

      def end_index(point_two, idx)
        @html_lines[idx[0]..@html_lines.size].each do |line|
          next unless line.include?(point_two)
          html_lines = @html_lines[idx[0]..@html_lines.size]
          idx[1] = idx[0] + html_lines.find_index(line)
          break if (idx[1]).positive?
        end
        idx
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
keppler-2.1.22 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.21 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.20 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.19 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.18 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.17 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.16 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.15 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.14 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.13 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.12 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.11 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.10 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.9 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.8 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.7 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.6 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb
keppler-2.1.5 installer/core/rockets/keppler_frontend/app/services/keppler_frontend/utils/code_search.rb