Class: CSVPlusPlus::Entities::CellReference

Inherits:
Entity
  • Object
show all
Defined in:
lib/csv_plus_plus/entities/cell_reference.rb

Overview

A reference to a cell

Constant Summary collapse

A1_NOTATION_REGEXP =
/(['\w]+!)?\w+:\w+/

Instance Attribute Summary collapse

Attributes inherited from Entity

#id, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

#method_missing, #respond_to_missing?

Constructor Details

#initialize(cell_reference) ⇒ CellReference

Returns a new instance of CellReference.

Parameters:

  • cell_reference (String)

    The cell reference in A1 format



43
44
45
46
47
# File 'lib/csv_plus_plus/entities/cell_reference.rb', line 43

def initialize(cell_reference)
  super(:cell_reference)

  @cell_reference = cell_reference
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CSVPlusPlus::Entities::Entity

Instance Attribute Details

#cell_referenceString (readonly)

The cell reference in A1 format

Returns:

  • (String)

    the current value of cell_reference



11
12
13
# File 'lib/csv_plus_plus/entities/cell_reference.rb', line 11

def cell_reference
  @cell_reference
end

Class Method Details

.from_index(cell_index:, row_index:) ⇒ CellReference

Create a CellReference to the given indexes

Parameters:

  • cell_index (Integer)

    The current cell index

  • row_index (Integer)

    The current row index

Returns:



23
24
25
26
27
28
# File 'lib/csv_plus_plus/entities/cell_reference.rb', line 23

def self.from_index(cell_index:, row_index:)
  return unless row_index || cell_index

  # I can't just extend this class due to circular references :(
  ::Class.new.extend(::CSVPlusPlus::Entities::ASTBuilder).ref(cell_index:, row_index:)
end

.valid_cell_reference?(cell_reference_string) ⇒ boolean

Does the given cell_reference_string conform to a valid cell reference?

https://developers.google.com/sheets/api/guides/concepts

Parameters:

  • cell_reference_string (::String)

    The string to check if it is a valid cell reference (we assume it’s in A1 notation but maybe can support R1C1)

Returns:

  • (boolean)


38
39
40
# File 'lib/csv_plus_plus/entities/cell_reference.rb', line 38

def self.valid_cell_reference?(cell_reference_string)
  !(cell_reference_string =~ ::CSVPlusPlus::Entities::CellReference::A1_NOTATION_REGEXP).nil?
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:



55
56
57
# File 'lib/csv_plus_plus/entities/cell_reference.rb', line 55

def ==(other)
  super && @cell_reference == other.cell_reference
end

#to_s::String

Returns:

  • (::String)


50
51
52
# File 'lib/csv_plus_plus/entities/cell_reference.rb', line 50

def to_s
  @cell_reference
end