Sha256: 98843ca1caec93fcd80bca2a042c5336a7a1e0b42cd5fd1f4a24f55f7ab12ac9
Contents?: true
Size: 682 Bytes
Versions: 46
Compression:
Stored size: 682 Bytes
Contents
module Lookbook class KeyValueTagParser < Service KEY_VALUE_REGEX = /^([^\s]+)\s+(.+)$/ attr_reader :text def initialize(text) @text = text.to_s end def call text.strip.match(KEY_VALUE_REGEX) do |matches| key = matches[1] value = begin YAML.safe_load(matches[2] || "~") rescue ::Psych::SyntaxError => exception raise ParserError.new("Invalid YAML in tag text '#{@text}'", scope: "key_value_tag.parser", original: exception) end return [key, value] end raise ParserError.new("Could not parse key:value pair from '#{@text}'", scope: "key_value_tag.parser") end end end
Version data entries
46 entries across 46 versions & 1 rubygems