Class: Sarif::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/sarif/address.rb

Overview

A physical or virtual address, or a range of addresses, in an ‘addressable region’ (memory or a binary file).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(absolute_address: -1,, relative_address: nil, length: nil, kind: nil, name: nil, fully_qualified_name: nil, offset_from_parent: nil, index: -1,, parent_index: -1,, properties: nil) ⇒ Address

Returns a new instance of Address.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/sarif/address.rb', line 8

def initialize(absolute_address: -1, relative_address: nil, length: nil, kind: nil, name: nil, fully_qualified_name: nil, offset_from_parent: nil, index: -1, parent_index: -1, properties: nil)
  @absolute_address = absolute_address
  @relative_address = relative_address
  @length = length
  @kind = kind
  @name = name
  @fully_qualified_name = fully_qualified_name
  @offset_from_parent = offset_from_parent
  @index = index
  @parent_index = parent_index
  @properties = properties
end

Instance Attribute Details

#absolute_addressObject

Returns the value of attribute absolute_address.



6
7
8
# File 'lib/sarif/address.rb', line 6

def absolute_address
  @absolute_address
end

#fully_qualified_nameObject

Returns the value of attribute fully_qualified_name.



6
7
8
# File 'lib/sarif/address.rb', line 6

def fully_qualified_name
  @fully_qualified_name
end

#indexObject

Returns the value of attribute index.



6
7
8
# File 'lib/sarif/address.rb', line 6

def index
  @index
end

#kindObject

Returns the value of attribute kind.



6
7
8
# File 'lib/sarif/address.rb', line 6

def kind
  @kind
end

#lengthObject

Returns the value of attribute length.



6
7
8
# File 'lib/sarif/address.rb', line 6

def length
  @length
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/sarif/address.rb', line 6

def name
  @name
end

#offset_from_parentObject

Returns the value of attribute offset_from_parent.



6
7
8
# File 'lib/sarif/address.rb', line 6

def offset_from_parent
  @offset_from_parent
end

#parent_indexObject

Returns the value of attribute parent_index.



6
7
8
# File 'lib/sarif/address.rb', line 6

def parent_index
  @parent_index
end

#propertiesObject

Returns the value of attribute properties.



6
7
8
# File 'lib/sarif/address.rb', line 6

def properties
  @properties
end

#relative_addressObject

Returns the value of attribute relative_address.



6
7
8
# File 'lib/sarif/address.rb', line 6

def relative_address
  @relative_address
end

Class Method Details

.from_hash(h) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sarif/address.rb', line 40

def self.from_hash(h)
  return nil if h.nil?
  new(
    absolute_address: h["absoluteAddress"] || -1,
    relative_address: h["relativeAddress"],
    length: h["length"],
    kind: h["kind"],
    name: h["name"],
    fully_qualified_name: h["fullyQualifiedName"],
    offset_from_parent: h["offsetFromParent"],
    index: h["index"] || -1,
    parent_index: h["parentIndex"] || -1,
    properties: h["properties"]
  )
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



56
57
58
59
# File 'lib/sarif/address.rb', line 56

def ==(other)
  return false unless other.is_a?(Address)
  @absolute_address == other.absolute_address && @relative_address == other.relative_address && @length == other.length && @kind == other.kind && @name == other.name && @fully_qualified_name == other.fully_qualified_name && @offset_from_parent == other.offset_from_parent && @index == other.index && @parent_index == other.parent_index && @properties == other.properties
end

#hashObject



63
64
65
# File 'lib/sarif/address.rb', line 63

def hash
  [@absolute_address, @relative_address, @length, @kind, @name, @fully_qualified_name, @offset_from_parent, @index, @parent_index, @properties].hash
end

#to_hObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sarif/address.rb', line 21

def to_h
  h = {}
  h["absoluteAddress"] = @absolute_address if @absolute_address && @absolute_address != -1
  h["relativeAddress"] = @relative_address unless @relative_address.nil?
  h["length"] = @length unless @length.nil?
  h["kind"] = @kind unless @kind.nil?
  h["name"] = @name unless @name.nil?
  h["fullyQualifiedName"] = @fully_qualified_name unless @fully_qualified_name.nil?
  h["offsetFromParent"] = @offset_from_parent unless @offset_from_parent.nil?
  h["index"] = @index if @index && @index != -1
  h["parentIndex"] = @parent_index if @parent_index && @parent_index != -1
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



36
37
38
# File 'lib/sarif/address.rb', line 36

def to_json(pretty: false)
  pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h)
end