# class Byebug::Printers::Base

Base printer

### Constants

SEPARATOR

### Public Instance Methods

type() click to toggle source

    # File lib/byebug/printers/base.rb, line 16
    def type
      self.class.name.split("::").last.downcase
    end

### Private Instance Methods

array_of_args(collection) { |item, index| ... } click to toggle source

    # File lib/byebug/printers/base.rb, line 55
    def array_of_args(collection, &_block)
      collection_with_index = collection.each.with_index
      collection_with_index.each_with_object([]) do |(item, index), array|
        args = yield item, index
        array << args if args
      end
    end

contents() click to toggle source

    # File lib/byebug/printers/base.rb, line 49
    def contents
      @contents ||= contents_files.each_with_object({}) do |filename, hash|
        hash[filename] = YAML.load_file(filename) || {}
      end
    end

contents_files() click to toggle source

    # File lib/byebug/printers/base.rb, line 63
    def contents_files
      [File.join(__dir__, "texts", "base.yml")]
    end

locate(path) click to toggle source

    # File lib/byebug/printers/base.rb, line 22
    def locate(path)
      result = nil
      contents.each_value do |contents|
        result = parts(path).reduce(contents) do |r, part|
          r&.key?(part) ? r[part] : nil
        end
        break if result
      end
      raise MissedPath, "Can't find part path '#{path}'" unless result

      result
    end

parts(path) click to toggle source

    # File lib/byebug/printers/base.rb, line 45
    def parts(path)
      path.split(SEPARATOR)
    end

translate(string, args = {}) click to toggle source

    # File lib/byebug/printers/base.rb, line 35
    def translate(string, args = {})
      # they may contain #{} string interpolation
      string.gsub(/\|\w+$/, "").gsub(/([^#]?){([^}]*)}/) do
        key = Regexp.last_match[2].to_s
        raise MissedArgument, "Missed argument #{key} for '#{string}'" unless args.key?(key.to_sym)

        "#{Regexp.last_match[1]}#{args[key.to_sym]}"
      end
    end