class AsciiTree::Word

Attributes

end_coordinate[R]
identity[R]
start_coordinate[R]
value[R]

Public Class Methods

new(identity:, value:, start_coordinate:, end_coordinate:) click to toggle source
# File lib/ascii_tree/word.rb, line 5
def initialize(identity:, value:, start_coordinate:, end_coordinate:)
  @identity         = identity
  @value            = value
  @start_coordinate = start_coordinate
  @end_coordinate   = end_coordinate
end

Public Instance Methods

==(other) click to toggle source
# File lib/ascii_tree/word.rb, line 12
def ==(other)
  identity == other.identity &&
    value == other.value &&
    start_coordinate == other.start_coordinate &&
    end_coordinate == other.end_coordinate
end
include?(coordinate) click to toggle source
# File lib/ascii_tree/word.rb, line 19
def include?(coordinate)
  same_line?(coordinate.y) && inside?(coordinate.x)
end

Private Instance Methods

inside?(x) click to toggle source
# File lib/ascii_tree/word.rb, line 29
def inside?(x)
  (start_coordinate.x..end_coordinate.x).include?(x)
end
same_line?(y) click to toggle source
# File lib/ascii_tree/word.rb, line 25
def same_line?(y)
  y == start_coordinate.y && y == end_coordinate.y
end