Sha256: 28c81dbb052ba20a54de1f5e22fbd6a8df2457ed078826ef50cfe4a714461150

Contents?: true

Size: 857 Bytes

Versions: 2

Compression:

Stored size: 857 Bytes

Contents

# frozen_string_literal: true

module DevSuite
  module Utils
    module Data
      module PathAccess
        module PathParser
          extend self

          def parse(path)
            return path if path.is_a?(Array)
            return parse_symbol_path(path) if path.is_a?(Symbol)
            return parse_string_path(path) if path.is_a?(String)

            [path]
          end

          private

          def parse_symbol_path(symbol_path)
            symbol_path.to_s.split(/\.|\[|\]/).reject(&:empty?).map { |part| parse_part(part) }
          end

          def parse_string_path(string_path)
            string_path.split(/\.|\[|\]/).reject(&:empty?).map { |part| parse_part(part) }
          end

          def parse_part(part)
            part.match?(/^\d+$/) ? part.to_i : part.to_sym
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dev_suite-0.2.13 lib/dev_suite/utils/data/path_access/path_parser.rb
dev_suite-0.2.12 lib/dev_suite/utils/data/path_access/path_parser.rb