Class: TreeHaver::Base::Point

Inherits:
Struct
  • Object
show all
Defined in:
lib/tree_haver/base/point.rb

Overview

Point struct for position information (row/column)

Provides a consistent interface for 0-based row/column positions. Compatible with both hash-style access and method access.

Examples:

point = TreeHaver::Base::Point.new(5, 10)
point.row      # => 5
point.column   # => 10
point[:row]    # => 5
point[:column] # => 10

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#columnObject

Returns the value of attribute column

Returns:

  • (Object)

    the current value of column



16
17
18
# File 'lib/tree_haver/base/point.rb', line 16

def column
  @column
end

#rowObject

Returns the value of attribute row

Returns:

  • (Object)

    the current value of row



16
17
18
# File 'lib/tree_haver/base/point.rb', line 16

def row
  @row
end

Instance Method Details

#[](key) ⇒ Integer?

Hash-style access for compatibility

Parameters:

  • key (Symbol, String)

    :row or :column

Returns:

  • (Integer, nil)


20
21
22
23
24
25
26
27
# File 'lib/tree_haver/base/point.rb', line 20

def [](key)
  case key
  when :row, "row", 0
    row
  when :column, "column", 1
    column
  end
end

#inspectString

Human-readable representation

Returns:

  • (String)


43
44
45
# File 'lib/tree_haver/base/point.rb', line 43

def inspect
  "#<TreeHaver::Base::Point row=#{row} column=#{column}>"
end

#to_hHash{Symbol => Integer}

Convert to hash

Returns:

  • (Hash{Symbol => Integer})


31
32
33
# File 'lib/tree_haver/base/point.rb', line 31

def to_h
  {row: row, column: column}
end

#to_sString

String representation

Returns:

  • (String)


37
38
39
# File 'lib/tree_haver/base/point.rb', line 37

def to_s
  "(#{row}, #{column})"
end