class PgExecArrayParams::SqlRefIndex
Calculates inclusive bounds of each element in a flattened list Bounds are one-based (as sql ref indexes), single value for non-arrays
- 1, [2, 3], 4, [5, 6, 7]
-
> [1, [2, 3], 4, [5, 7]]¶ ↑
Attributes
array[R]
Public Class Methods
new(array)
click to toggle source
# File lib/pg_exec_array_params/sql_ref_index.rb, line 10 def initialize(array) @array = array @extra_items = 0 end
Public Instance Methods
[](key)
click to toggle source
# File lib/pg_exec_array_params/sql_ref_index.rb, line 15 def [](key) sql_ref_index[key] end
sql_ref_index()
click to toggle source
# File lib/pg_exec_array_params/sql_ref_index.rb, line 19 def sql_ref_index @sql_ref_index ||= array.map.with_index(1) do |item, idx| if item.is_a?(Array) add_extra_items = item.size add_extra_items -= 1 if add_extra_items.positive? [idx + @extra_items, idx + (@extra_items += add_extra_items)] else idx + @extra_items end end end