Class: Vastlint::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/vastlint/result.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version:, issues:, summary:) ⇒ Result

Returns a new instance of Result.



36
37
38
39
40
# File 'lib/vastlint/result.rb', line 36

def initialize(version:, issues:, summary:)
  @version = version
  @issues = issues
  @summary = summary
end

Instance Attribute Details

#issuesObject (readonly)

Returns the value of attribute issues.



7
8
9
# File 'lib/vastlint/result.rb', line 7

def issues
  @issues
end

#summaryObject (readonly)

Returns the value of attribute summary.



7
8
9
# File 'lib/vastlint/result.rb', line 7

def summary
  @summary
end

#versionObject (readonly)

Returns the value of attribute version.



7
8
9
# File 'lib/vastlint/result.rb', line 7

def version
  @version
end

Class Method Details

.from_json(json_payload) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vastlint/result.rb', line 9

def self.from_json(json_payload)
  parsed = JSON.parse(json_payload)

  new(
    version: parsed["version"],
    issues: Array(parsed["issues"]).map do |issue|
      Issue.new(
        id: issue["id"],
        severity: issue["severity"],
        message: issue["message"],
        path: issue["path"],
        spec_ref: issue["spec_ref"],
        line: issue["line"],
        col: issue["col"]
      )
    end,
    summary: Summary.new(
      errors: parsed.fetch("summary").fetch("errors"),
      warnings: parsed.fetch("summary").fetch("warnings"),
      infos: parsed.fetch("summary").fetch("infos"),
      valid: parsed.fetch("summary").fetch("valid")
    )
  )
rescue JSON::ParserError => error
  raise LibraryError, "failed to parse vastlint result JSON: #{error.message}"
end

Instance Method Details

#as_jsonObject



46
47
48
49
50
51
52
# File 'lib/vastlint/result.rb', line 46

def as_json(*)
  {
    version: version,
    issues: issues.map(&:as_json),
    summary: summary.as_json
  }
end

#to_hObject



54
55
56
# File 'lib/vastlint/result.rb', line 54

def to_h
  as_json
end

#to_json(*args) ⇒ Object



58
59
60
# File 'lib/vastlint/result.rb', line 58

def to_json(*args)
  JSON.generate(as_json, *args)
end

#valid?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/vastlint/result.rb', line 42

def valid?
  summary.valid?
end