Class: CSVPlusPlus::Entities::Reference
Overview
A reference to something - this is typically either a cell reference (handled by A1Reference
) or a reference to a variable.
One sticking point with the design of this class is that we don’t know if a reference is a variable reference unless we look at currently defined variables and see if there is one by that name. Since all cell references can be a valid variable name, we can’t be sure which is which. So we delegate that decision as late as possible
-
in #evaluate
Instance Attribute Summary collapse
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
-
#scoped_to_expand ⇒ Expand?
readonly
If set, the expand in which this variable is scoped to.
Instance Method Summary collapse
- #==(other) ⇒ boolean
- #a1_ref ⇒ A1Reference
-
#evaluate(position) ⇒ ::String
Get the A1-style cell reference.
- #id ⇒ Symbol
-
#initialize(ref: nil, a1_ref: nil) ⇒ Reference
constructor
Either
ref
,cell_index
orrow_index
must be specified.
Methods included from HasIdentifier
Constructor Details
#initialize(ref: nil, a1_ref: nil) ⇒ Reference
Either ref
, cell_index
or row_index
must be specified.
31 32 33 34 35 36 37 38 |
# File 'lib/csv_plus_plus/entities/reference.rb', line 31 def initialize(ref: nil, a1_ref: nil) super() raise(::ArgumentError, 'Must specify :ref or :a1_ref') unless ref || a1_ref @ref = ref @a1_ref = a1_ref end |
Instance Attribute Details
#ref ⇒ Object (readonly)
Returns the value of attribute ref.
21 22 23 |
# File 'lib/csv_plus_plus/entities/reference.rb', line 21 def ref @ref end |
#scoped_to_expand ⇒ Expand? (readonly)
If set, the expand in which this variable is scoped to. It cannot be resolved outside of the given expand.
16 17 18 |
# File 'lib/csv_plus_plus/entities/reference.rb', line 16 def @scoped_to_expand end |
Instance Method Details
#==(other) ⇒ boolean
44 45 46 47 48 49 50 51 |
# File 'lib/csv_plus_plus/entities/reference.rb', line 44 def ==(other) case other when self.class a1_ref == other.a1_ref else false end end |
#a1_ref ⇒ A1Reference
55 56 57 |
# File 'lib/csv_plus_plus/entities/reference.rb', line 55 def a1_ref @a1_ref ||= ::CSVPlusPlus::A1Reference.new(ref: ::T.must(ref)) end |
#evaluate(position) ⇒ ::String
Get the A1-style cell reference
65 66 67 68 |
# File 'lib/csv_plus_plus/entities/reference.rb', line 65 def evaluate(position) # TODO: ugh make to_a1_ref not return a nil ref || a1_ref.to_a1_ref(position) || '' end |
#id ⇒ Symbol
72 73 74 |
# File 'lib/csv_plus_plus/entities/reference.rb', line 72 def id ref && identifier(::T.must(ref).to_sym) end |