Class: CC::CLI::Marker

Inherits:
Object
  • Object
show all
Defined in:
lib/cc/cli/test.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, line_text) ⇒ Marker

Returns a new instance of Marker.



64
65
66
67
68
# File 'lib/cc/cli/test.rb', line 64

def initialize(line, line_text)
  @line = line
  @line_text = line_text
  @issue = issue
end

Instance Attribute Details

#issueObject

Returns the value of attribute issue.



62
63
64
# File 'lib/cc/cli/test.rb', line 62

def issue
  @issue
end

#lineObject (readonly)

Returns the value of attribute line.



61
62
63
# File 'lib/cc/cli/test.rb', line 61

def line
  @line
end

#line_textObject (readonly)

Returns the value of attribute line_text.



61
62
63
# File 'lib/cc/cli/test.rb', line 61

def line_text
  @line_text
end

Class Method Details

.attrs_from_marker(text) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cc/cli/test.rb', line 30

def self.attrs_from_marker(text)
  if text.blank?
    {}
  else
    matches = text.scan(/([a-z\._-]+)=(?:(")((?:\\.|[^"])*)"|([^\s]*))/).map(&:compact)

    key_values = matches.map do |match|
      munge_match(match)
    end

    Hash[key_values]
  end
end

.from_text(engine_name, test_file, line_number, text) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cc/cli/test.rb', line 7

def self.from_text(engine_name, test_file, line_number, text)
  marker = Marker.new(line_number, text)
  attrs = attrs_from_marker(text.sub(/^.*\[issue\] ?/, ""))

  marker.issue = attrs.merge(
    "engine_name" => engine_name,
    "location" => {
      "path" => test_file,
      "lines" => {
        "begin" => line_number + 1,
        "end" => line_number + 1,
      },
    },
  )

  if marker.issue["category"]
    marker.issue["categories"] = Array.wrap(marker.issue["category"])
    marker.issue.delete("category")
  end

  marker
end

.munge_match(match) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/cc/cli/test.rb', line 44

def self.munge_match(match)
  if match.size == 3 # Quoted
    key, _, value = match
    value = '"' + value + '"'
  else
    key, value = match
  end

  [key, munge_value(value)]
end

.munge_value(value) ⇒ Object



55
56
57
58
59
# File 'lib/cc/cli/test.rb', line 55

def self.munge_value(value)
  JSON.load(value)
rescue JSON::ParserError
  value
end