NeoCSV: Interdependent Field

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

NeoCSV: Interdependent Field

Sean P. DeNigris
Administrator
How (if at all) can one handle parsing when fields depend on one another? It seems that it would be helpful to have access to the currently constructed object in field converters, but it doesn't look like that is possible...

Thanks!
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: NeoCSV: Interdependent Field

Sven Van Caekenberghe-2
Hi Sean,

Could you elaborate a bit on the concrete use case (or a similar example) ?

My first response would be to add some intelligence inside your objects. Say you have a person object, setting the first name would set the initial too, unless it was already set, and it could be overwritten later on.

Sven

PS: I did see you other remark, and I looked at it, but I did not yet reply.

> On 05 Sep 2016, at 16:36, Sean P. DeNigris <[hidden email]> wrote:
>
> How (if at all) can one handle parsing when fields depend on one another? It
> seems that it would be helpful to have access to the currently constructed
> object in field converters, but it doesn't look like that is possible...
>
> Thanks!
>
>
>
> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/NeoCSV-Interdependent-Field-tp4914190.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: NeoCSV: Interdependent Field

Sean P. DeNigris
Administrator
Sven Van Caekenberghe-2 wrote
Could you elaborate a bit on the concrete use case (or a similar example) ?
Sure. Say the data rows are events which contain, among other things, the following fields:
-a date
- an employeeID
- a title (as in position in the company e.g. CEO).

Usually, the title is filled in, but sometimes it's missing. When it's missing, it can be calculated by `(employees detectID: employeeID) titleOn: timestamp`*, but if it's present, you should just use the value in the field because the lookup is inconsistent and expensive.

Thanks for following up!

* The timestamp is necessary because you're actually searching through the employment history to see the title on that particular date in the past.
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: NeoCSV: Interdependent Field

Sven Van Caekenberghe-2

> On 05 Sep 2016, at 18:03, Sean P. DeNigris <[hidden email]> wrote:
>
> Sven Van Caekenberghe-2 wrote
>> Could you elaborate a bit on the concrete use case (or a similar example)
>> ?
>
> Sure. Say the data rows are events which contain, among other things, the
> following fields:
> -a date
> - an employeeID
> - a title (as in position in the company e.g. CEO).
>
> Usually, the title is filled in, but sometimes it's missing. When it's
> missing, it can be calculated by `(employees detectID: employeeID) titleOn:
> timestamp`*, but if it's present, you should just use the value in the field
> because the lookup is inconsistent and expensive.
>
> Thanks for following up!
>
> * The timestamp is necessary because you're actually searching through the
> employment history to see the title on that particular date in the past.

Could you write your #title accessor then as

title
  ^ title ifNil: [ title := (employees detectID: employeeID) titleOn:
timestamp ]

?

Or do you then again have problems with the #emptyFieldValue: from your previous issue ?


Reply | Threaded
Open this post in threaded view
|

Re: NeoCSV: Interdependent Field

Sean P. DeNigris
Administrator
Sven Van Caekenberghe-2 wrote
Could you write your #title accessor then as
That's what I ended up doing :) I just wondered if there was a better way. Thinking out loud, is there any harm in the added flexibility of passing the object-in-progress as well as the string to the converter via #cull:cull:?
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: NeoCSV: Interdependent Field

Sven Van Caekenberghe-2

> On 05 Sep 2016, at 18:24, Sean P. DeNigris <[hidden email]> wrote:
>
> Sven Van Caekenberghe-2 wrote
>> Could you write your #title accessor then as
>
> That's what I ended up doing :)

OK.

> I just wondered if there was a better way.
> Thinking out loud, is there any harm in the added flexibility of passing the
> object-in-progress as well as the string to the converter via #cull:cull:?

I guess it would be slower.

> -----
> Cheers,
> Sean
> --
> View this message in context: http://forum.world.st/NeoCSV-Interdependent-Field-tp4914190p4914206.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>