module

CWE

JSON serialization for CWE::Weakness.

The emitted shape is stable and snake_case. Empty arrays and nil scalars are omitted so a serialized entry is concise. The catalog identifier ("CWE-79") is emitted as "cweId" alongside the integer "id" for tooling that wants either form.

JSON.parse(CWE.find!(79).to_json)["cweId"].as_s # => "CWE-79"

Constants

ID_PATTERN = /\A(?:[Cc][Ww][Ee][-_: ])?(\d+)\z/

The numeric portion of a CWE id, e.g. "CWE-79", "cwe-79", " 79 ", or "79". Returns nil if the input does not match.

The prefix is case-insensitive and must be followed by exactly one separator โ€” -, _, :, or a single space. Surrounding whitespace is stripped first; embedded whitespace, repeated separators, and the separator-less "CWE79" form are all rejected. Numbers too large for an Int32 return nil rather than overflowing.

VERSION = "0.1.0"

Class methods

[](id : Int) : Weakness

CWE[X] and CWE[X]? indexing.

Source
[](id : String) : Weakness
Source
[]?(id : Int) : Weakness | Nil
Source
[]?(id : String) : Weakness | Nil
Source
all

All weaknesses, sorted by numeric id.

Source
ancestors_of(id : Int, view_id : Int | Nil = nil, max_depth : Int = 32) : Array(Weakness)
Source
ancestors_of(id : String, view_id : Int | Nil = nil, max_depth : Int = 32) : Array(Weakness)
Source
catalog

Default catalog instance. The first call lazily parses the embedded JSON blob; subsequent calls return the same instance.

Source
catalog_version

The MITRE catalog version embedded in this build (e.g. "4.20").

Source
categories
Source
category(id : Int) : Category | Nil
Source
category(id : String) : Category | Nil
Source
category!(id : Int) : Category
Source
category!(id : String) : Category
Source
children_of(id : Int, view_id : Int | Nil = nil) : Array(Weakness)
Source
children_of(id : String, view_id : Int | Nil = nil) : Array(Weakness)
Source
descendants_of(id : Int, view_id : Int | Nil = nil, max_depth : Int = 32) : Array(Weakness)
Source
descendants_of(id : String, view_id : Int | Nil = nil, max_depth : Int = 32) : Array(Weakness)
Source
each
Source
entry(id : Int) : Weakness | Category | View | Nil

Look up any entry by id: Weakness, Category, or View.

Source
entry(id : String) : Weakness | Category | View | Nil
Source
external_reference(id : String) : ExternalReference | Nil

Resolve a REF-N citation id to its full record. Returns nil if the id is not in the registry.

Source
external_reference!(id : String) : ExternalReference
Source
external_references

All catalog-level citations (the <External_References> block in the MITRE XML). Empty when the build wasn't given the XML.

Source
find(id : Int) : Weakness | Nil

Look up a weakness by integer id (e.g. 79) or CWE string ("CWE-79", "cwe-79", "79"). Returns nil if not found.

Source
find(id : String) : Weakness | Nil
Source
find!(id : Int) : Weakness

Raising variants โ€” NotFoundError if the id is not in the catalog, ParseError if the string is not a CWE id.

Source
find!(id : String) : Weakness
Source
includes?(id : Int) : Bool
Source
includes?(id : String) : Bool
Source
members_of(id : Int) : Array(Weakness)

Resolved member weaknesses of a Category or View.

Source
members_of(id : String) : Array(Weakness)
Source
parents_of(id : Int, view_id : Int | Nil = nil) : Array(Weakness)

Traversal accepts the same id forms as find โ€” 79, "79", "CWE-79". max_depth bounds the transitive walks; the real CWE hierarchy is only 3-4 levels deep, so the default is a guard against pathological catalogs rather than something callers normally set.

Source
parents_of(id : String, view_id : Int | Nil = nil) : Array(Weakness)
Source
parse_id(input : String) : Int32

Raising variant of parse_id?.

Source
parse_id?(input : String) : Int32 | Nil
Source
pillar_of(id : Int) : Weakness | Nil
Source
pillar_of(id : String) : Weakness | Nil
Source
search(query : String) : Array(Weakness)

Case-insensitive substring search across name, descriptions, and alternate terms.

Source
search_by_name(query : String) : Array(Weakness)
Source
size
Source
view(id : Int) : View | Nil
Source
view(id : String) : View | Nil
Source
view!(id : Int) : View
Source
view!(id : String) : View
Source
views
Source
with_abstraction(level : Abstraction) : Array(Weakness)
Source
with_status(status : Status) : Array(Weakness)
Source

Nested types