Sha256: c362044e1b837e123b1f3a065d1356fb1f5a659961d630ebbd190c548fc4645e
Contents?: true
Size: 775 Bytes
Versions: 58
Compression:
Stored size: 775 Bytes
Contents
# frozen_string_literal: true module Krane class LabelSelector def self.parse(string) selector = {} string.split(',').each do |kvp| key, value = kvp.split('=', 2) if key.blank? raise ArgumentError, "key is blank" end if key.end_with?("!") raise ArgumentError, "!= selectors are not supported" end if value&.start_with?("=") raise ArgumentError, "== selectors are not supported" end selector[key] = value end new(selector) end def initialize(hash) @selector = hash end def to_h @selector end def to_s return "" if @selector.nil? @selector.map { |k, v| "#{k}=#{v}" }.join(",") end end end
Version data entries
58 entries across 58 versions & 3 rubygems