Class: Furud::Area

Inherits:
Data
  • Object
show all
Defined in:
lib/furud/types.rb,
sig/furud.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sheet: nil, top:, left:, bottom:, right:) ⇒ Area

Returns a new instance of Area.

Parameters:

  • sheet: (String, nil) (defaults to: nil)
  • top: (Integer)
  • left: (Integer)
  • bottom: (Integer)
  • right: (Integer)

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
# File 'lib/furud/types.rb', line 14

def initialize(sheet: nil, top:, left:, bottom:, right:)
  values = [top, left, bottom, right].map { |value| Integer(value) }
  raise ArgumentError, "area coordinates must be positive" unless values.all?(&:positive?)

  top, left, bottom, right = values
  super(sheet: sheet&.to_s, top: [top, bottom].min, left: [left, right].min,
        bottom: [top, bottom].max, right: [left, right].max)
end

Instance Attribute Details

#bottom ⇒ Object (readonly)

Returns the value of attribute bottom

Returns:

  • (Object) —

    the current value of bottom



13
14
15
# File 'lib/furud/types.rb', line 13

def bottom
  @bottom
end

#left ⇒ Object (readonly)

Returns the value of attribute left

Returns:

  • (Object) —

    the current value of left



13
14
15
# File 'lib/furud/types.rb', line 13

def left
  @left
end

#right ⇒ Object (readonly)

Returns the value of attribute right

Returns:

  • (Object) —

    the current value of right



13
14
15
# File 'lib/furud/types.rb', line 13

def right
  @right
end

#sheet ⇒ Object (readonly)

Returns the value of attribute sheet

Returns:

  • (Object) —

    the current value of sheet



13
14
15
# File 'lib/furud/types.rb', line 13

def sheet
  @sheet
end

#top ⇒ Object (readonly)

Returns the value of attribute top

Returns:

  • (Object) —

    the current value of top



13
14
15
# File 'lib/furud/types.rb', line 13

def top
  @top
end

Instance Method Details

#include?(reference) ⇒ Boolean

Parameters:

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/furud/types.rb', line 23

def include?(reference)
  (sheet.nil? || reference.sheet == sheet) && reference.row.between?(top, bottom) &&
    reference.column.between?(left, right)
end