frictionlessdata / tableschema-rb

A Ruby library for working with JSON Table Schema.
MIT License
12 stars 10 forks source link

Replace the types public API with the Field public API #9

Closed pwalsh closed 8 years ago

pwalsh commented 8 years ago

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_* to cast_* semantics occurred at around the same time. Example.

it would be good to move the Ruby lib to the Field API.

# fields (new)
Field({'type': 'number'}).cast_value()

# types (old)
types.NumberType({'type': 'number'}).convert_value()

cc @roll

roll commented 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 commented 8 years ago

@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?

pezholio commented 8 years ago

That's right 👍

roll commented 8 years ago

Thanks! Also starting to understand Ruby a little bit (found load_fields!=) :+1:

pezholio commented 8 years ago

Yeah, it wasn't in the most sensible place before. Makes much more sense to have it in Model