Class: Insika::Evidence::Spec

Inherits:
Data
  • Object
show all
Defined in:
lib/insika/evidence.rb

Overview

The declaration (D1/C2.1). Parses three authorable shapes:

{ "evidence": "products" }                             // bare kind
{ "evidence": { "kind": "products" } }                 // full form
{ "evidence": { "kind": "products",
              "items": "results",
              "attachments": "cards" } }             // non-default paths

kind is the PILOT PACK's value, never a gem constant (the engine owns nothing about product shape).

Constant Summary collapse

PATH_RE =
/\A[a-zA-Z0-9_]+(?:\.[a-zA-Z0-9_]+)*\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attachments_pathObject (readonly)

Returns the value of attribute attachments_path

Returns:

  • (Object)

    the current value of attachments_path



29
30
31
# File 'lib/insika/evidence.rb', line 29

def attachments_path
  @attachments_path
end

#items_pathObject (readonly)

Returns the value of attribute items_path

Returns:

  • (Object)

    the current value of items_path



29
30
31
# File 'lib/insika/evidence.rb', line 29

def items_path
  @items_path
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



29
30
31
# File 'lib/insika/evidence.rb', line 29

def kind
  @kind
end

Class Method Details

.parse(raw) ⇒ Object

String | Hash | nil -> Spec | nil. Raises ValidationError on a blank kind or an empty/ill-formed path. All at ingestion, never at the turn.



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/insika/evidence.rb', line 34

def self.parse(raw)
  return nil if raw.nil? || raw == false

  h = raw.is_a?(String) ? { "kind" => raw } : Coercion.deep_stringify(raw)
  h = h.is_a?(Hash) ? h : {}
  kind = Coercion.presence(h["kind"])
  raise Insika::ValidationError, "evidence.kind is required" if kind.nil?

  items = presence_path(h["items"], "items")
  attachments = presence_path(h["attachments"], "attachments")
  new(kind: kind, items_path: items, attachments_path: attachments)
end

Instance Method Details

#to_hObject



47
48
49
# File 'lib/insika/evidence.rb', line 47

def to_h
  { "kind" => kind, "items" => items_path, "attachments" => attachments_path }.compact
end