Class: Kiba::Extend::Transforms::Cspace::Valuationcontrolrefnumber

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/transforms/cspace/valuationcontrolrefnumber.rb

Overview

Generates typical pattern of ValuationcontrolRefNumbers based on year in value date, where available. For each year, the procedure data is sorted by the full date value, and the reference number value is incremented.

The typical number pattern used is the location record pattern from the Valuation Control number autogenerator in the UI. The pattern is:

  • VC (customizable via the prefix parameter)
  • 4-digit year (for rows with no date, the value given for nodateval will be inserted here)
  • . (preincrementsegment param)
  • autoincrementing digit

ASSUMPTIONS OF THIS TRANSFORM

  • You will have already reduced the output to one row per valuation control to be created in CollectionSpace
  • You will have used DateValue::ForceDayPrecision or some other method to create a field containing only blank values and valid ISO 8601 dates to be mapped to the unstructured date valuedate field in CollectionSpace

SORTING, or, how the end digit gets incremented within a year

See IdGenerator::YearBasedIncrementing for sorting details.

Examples:

With default sorter

# Used in pipeline as:
# transform Cspace::Valuationcontrolrefnumber,
#   datefield: :d,
#   target: :tada
xform = Cspace::Valuationcontrolrefnumber.new(
  datefield: :d,
  target: :tada
)
input = [
  {d: "2007-12-13", i: "a"},
  {d: "2000-05-23", i: "z"},
  {d: "2000-01-01", i: "c"},
  {d: "", i: "q"},
  {d: "2000-05-23", i: "g"},
  {d: "2007-10-31", i: "f"},
  {d: "2000-12-14", i: "h"},
  {d: "2000-05-23", i: "d"},
  {d: nil, i: "y"},
  {d: "2017-02-04", i: "x"}
]
result = Kiba::StreamingRunner.transform_stream(input, xform)
  .map{ |row| row }
expected = [
  {d: "2007-10-31", i: "f", tada: "VC2007.1"},
  {d: "2007-12-13", i: "a", tada: "VC2007.2"},
  {d: "2000-01-01", i: "c", tada: "VC2000.1"},
  {d: "2000-05-23", i: "z", tada: "VC2000.2"},
  {d: "2000-05-23", i: "g", tada: "VC2000.3"},
  {d: "2000-05-23", i: "d", tada: "VC2000.4"},
  {d: "2000-12-14", i: "h", tada: "VC2000.5"},
  {d: "", i: "q", tada: "VC0000.1"},
  {d: nil, i: "y", tada: "VC0000.2"},
  {d: "2017-02-04", i: "x", tada: "VC2017.1"}
]
expect(result).to eq(expected)

Instance Method Summary collapse

Constructor Details

#initialize(datefield:, prefix: "VC", nodateval: "0000", preincrementsegment: ".", target: :valuationcontrolrefnumber, sorter: nil) ⇒ Valuationcontrolrefnumber

Returns a new instance of Valuationcontrolrefnumber.

Parameters:

  • datefield (Symbol)

    field containing valid ISO 8601 dates and blank values only

  • target (Symbol) (defaults to: :valuationcontrolrefnumber)

    field in which to write the generated value

  • prefix (String) (defaults to: "VC")

    initial segment of generated value

  • preincrementsegment (String) (defaults to: ".")

    optional segment of number after the year or nodateval and before the incrementing segment

  • nodateval (String) (defaults to: "0000")

    value inserted instead of the year, if datefield is blank

  • sorter (Lambda) (defaults to: nil)

    taking rows and datefield args, and returning sorted rows



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/kiba/extend/transforms/cspace/valuationcontrolrefnumber.rb', line 81

def initialize(datefield:,
  prefix: "VC",
  nodateval: "0000",
  preincrementsegment: ".",
  target: :valuationcontrolrefnumber,
  sorter: nil)
  @generator = IdGenerator::YearBasedIncrementing.new(
    datefield: datefield,
    prefix: prefix,
    nodateval: nodateval,
    preincrementsegment: preincrementsegment,
    target: target,
    sorter: sorter
  )
end

Instance Method Details

#closeObject



101
102
103
104
# File 'lib/kiba/extend/transforms/cspace/valuationcontrolrefnumber.rb', line 101

def close
  generator.finalized_rows
    .each { |row| yield row }
end

#process(row) ⇒ Object



97
98
99
# File 'lib/kiba/extend/transforms/cspace/valuationcontrolrefnumber.rb', line 97

def process(row)
  generator.process(row)
end