Class: Sarif::Rectangle

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

Overview

An area within an image.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(top: nil, left: nil, bottom: nil, right: nil, message: nil, properties: nil) ⇒ Rectangle

Returns a new instance of Rectangle.



8
9
10
11
12
13
14
15
# File 'lib/sarif/rectangle.rb', line 8

def initialize(top: nil, left: nil, bottom: nil, right: nil, message: nil, properties: nil)
  @top = top
  @left = left
  @bottom = bottom
  @right = right
  @message = message
  @properties = properties
end

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



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

def bottom
  @bottom
end

#leftObject

Returns the value of attribute left.



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

def left
  @left
end

#messageObject

Returns the value of attribute message.



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

def message
  @message
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#rightObject

Returns the value of attribute right.



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

def right
  @right
end

#topObject

Returns the value of attribute top.



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

def top
  @top
end

Class Method Details

.from_hash(h) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sarif/rectangle.rb', line 32

def self.from_hash(h)
  return nil if h.nil?
  new(
    top: h["top"],
    left: h["left"],
    bottom: h["bottom"],
    right: h["right"],
    message: Message.from_hash(h["message"]),
    properties: h["properties"]
  )
end

Instance Method Details

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



44
45
46
47
# File 'lib/sarif/rectangle.rb', line 44

def ==(other)
  return false unless other.is_a?(Rectangle)
  @top == other.top && @left == other.left && @bottom == other.bottom && @right == other.right && @message == other.message && @properties == other.properties
end

#hashObject



51
52
53
# File 'lib/sarif/rectangle.rb', line 51

def hash
  [@top, @left, @bottom, @right, @message, @properties].hash
end

#to_hObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/sarif/rectangle.rb', line 17

def to_h
  h = {}
  h["top"] = @top unless @top.nil?
  h["left"] = @left unless @left.nil?
  h["bottom"] = @bottom unless @bottom.nil?
  h["right"] = @right unless @right.nil?
  h["message"] = @message&.to_h unless @message.nil?
  h["properties"] = @properties unless @properties.nil?
  h
end

#to_json(pretty: false) ⇒ Object



28
29
30
# File 'lib/sarif/rectangle.rb', line 28

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