Class: Shojiku::Diagnostic
- Inherits:
-
Object
- Object
- Shojiku::Diagnostic
- Defined in:
- lib/shojiku/diagnostic.rb
Overview
One thing the engine noticed about a document.
Passed through, never interpreted. code and args are the engine's
frozen contract — a translating consumer renders its own message from
them — so this class parses the wire and stops. It does not translate, it
does not re-classify, and it never becomes an exception: a render that
warns still succeeded, and a render that failed says why in these.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
Class Method Summary collapse
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(item) ⇒ Diagnostic
constructor
A new instance of Diagnostic.
- #to_s ⇒ Object
- #warning? ⇒ Boolean
Constructor Details
#initialize(item) ⇒ Diagnostic
Returns a new instance of Diagnostic.
21 22 23 24 25 26 27 28 29 |
# File 'lib/shojiku/diagnostic.rb', line 21 def initialize(item) @severity = item["severity"] @code = item["code"] @category = item["category"] @message = item["message"] @path = item["path"] @args = item["args"] || {} @origin = item["origin"] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
12 13 14 |
# File 'lib/shojiku/diagnostic.rb', line 12 def args @args end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
12 13 14 |
# File 'lib/shojiku/diagnostic.rb', line 12 def category @category end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
12 13 14 |
# File 'lib/shojiku/diagnostic.rb', line 12 def code @code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
12 13 14 |
# File 'lib/shojiku/diagnostic.rb', line 12 def @message end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
12 13 14 |
# File 'lib/shojiku/diagnostic.rb', line 12 def origin @origin end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/shojiku/diagnostic.rb', line 12 def path @path end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
12 13 14 |
# File 'lib/shojiku/diagnostic.rb', line 12 def severity @severity end |
Class Method Details
.parse(json) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/shojiku/diagnostic.rb', line 14 def self.parse(json) return [] if json.nil? || json.empty? items = JSON.parse(json)["items"] Array(items).map { |item| new(item) } end |
Instance Method Details
#error? ⇒ Boolean
31 32 33 |
# File 'lib/shojiku/diagnostic.rb', line 31 def error? @severity == "error" end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/shojiku/diagnostic.rb', line 39 def to_s [@path, @message].compact.join(": ") end |
#warning? ⇒ Boolean
35 36 37 |
# File 'lib/shojiku/diagnostic.rb', line 35 def warning? @severity == "warning" end |