class ProbeDockProbe::Annotation

Constants

ANNOTATION_REGEXP
BASE_REGEXP_STRING
STRIP_ANNOTATION_REGEXP

Attributes

active[R]
category[R]
key[R]
tags[R]
tickets[R]

Public Class Methods

new(str) click to toggle source
# File lib/probe_dock_ruby/annotation.rb, line 9
def initialize(str)
  parse(str)
end
strip_annotations(test_name) click to toggle source
# File lib/probe_dock_ruby/annotation.rb, line 22
def self.strip_annotations(test_name)
  test_name.gsub(STRIP_ANNOTATION_REGEXP, '')
end

Public Instance Methods

merge!(annotation) click to toggle source
# File lib/probe_dock_ruby/annotation.rb, line 13
def merge!(annotation)
  @key = annotation.key if annotation.key
  @category = annotation.category if annotation.category
  @active = annotation.active unless annotation.active.nil?
  @tags = (@tags + annotation.tags).compact.collect(&:to_s).uniq
  @tickets = (@tickets + annotation.tickets).compact.collect(&:to_s).uniq
  self
end

Private Instance Methods

keyword_regexp(keyword) click to toggle source
# File lib/probe_dock_ruby/annotation.rb, line 62
def keyword_regexp(keyword)
  /#{keyword}=(?:(?<#{keyword}>[^"'\s]+)|["']?(?<#{keyword}>[^"']+)["']?)/
end
parse(str) click to toggle source
# File lib/probe_dock_ruby/annotation.rb, line 28
def parse(str)
  @key = nil
  @category = nil
  @tags = []
  @tickets = []
  @active = nil

  loop do
    match = str.match(ANNOTATION_REGEXP)

    if match
      text = match[1]

      if text.match(/^[a-z0-9]+$/)
        @key = text
      else
        @key = parse_annotation_value(text, 'key')
        @category = parse_annotation_value(text, 'category')
        parse_annotation_list(text, 'tag', @tags)
        parse_annotation_list(text, 'ticket', @tickets)

        active = text.match(/active=["']?(1|0|true|false|yes|no|t|f|y|n)["']?/i)
        if active
          @active = !active[1].match(/^(1|y|yes|t|true)$/i).nil?
        end
      end

      str = str.sub(ANNOTATION_REGEXP, '')
    else
      break
    end
  end
end
parse_annotation_list(text, keyword, values) click to toggle source
# File lib/probe_dock_ruby/annotation.rb, line 71
def parse_annotation_list(text, keyword, values)
  regexp = keyword_regexp(keyword)

  loop do
    match = text.match(regexp)

    if match
      values.push(match[keyword]) unless values.include?(match[keyword])
      text = text.sub(regexp, '')
    end

    break unless match
  end
end
parse_annotation_value(text, keyword) click to toggle source
# File lib/probe_dock_ruby/annotation.rb, line 66
def parse_annotation_value(text, keyword)
  match = text.match(keyword_regexp(keyword))
  match ? match[keyword] : nil
end