Closed pwalsh closed 8 years ago
This API also allows to return to user Field
instance from Schema
:
schema = Schema('descriptor.json')
field = schema.get_field('name') # the same for schema.fields etc
field.name
field.cast_value('value')
It's more useful to the user than just a dict. You could see it on the stack reference - https://github.com/frictionlessdata/project/issues/289 (also there are some discrepancies - no Schema.descriptor
in rb etc - because both works was going in parallel).
PS.
I suppose one important thing - we're trying to use descriptor
term consistently for argument names - Schema(descriptor), Field(descriptor), DataPackage(descriptor), Resource(descriptor)
.
@roll The schema and field connections are defined in https://github.com/theodi/jsontableschema.rb/blob/feature-add-field/lib/jsontableschema/model.rb - which is a Ruby module which is included in schema.rb - I've split a lot of things out into modules, which keeps things neater.
@pezholio
So when we iterate over schema.fields
we get Fields instances. Correct? The same for schema.get_field() -> Field
etc?
That's right 👍
Thanks! Also starting to understand Ruby a little bit (found load_fields!
=)
:+1:
Yeah, it wasn't in the most sensible place before. Makes much more sense to have it in Model
In the reference implementation we moved from exposing types to exposing a Field API. This was happening at the same time as the ruby port, so understandably is not here.
Also I think the change from
convert_*
tocast_*
semantics occurred at around the same time. Example.it would be good to move the Ruby lib to the Field API.
cc @roll