Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deferred table header and column mappings #163

Merged
merged 7 commits into from
Nov 19, 2011

Conversation

richardlawrence
Copy link
Contributor

I'd like table header and column mappings to work with #rows_hash, treating the values in the left column as headers and the values in the right column as column values. In order to support this, I changed Table to defer execution of mappings until #hashes or #diff! is called so that the table can be transposed first if necessary. The only change I made to existing specs was to add a call to #hashes for those specs that expected a mapping to raise an error.

Sorry about the wire_protocol.feature change being part of this. I tried to back out a change from another issue, but can't seem to get it removed completely.

@aslakhellesoy aslakhellesoy merged commit 9072074 into cucumber:master Nov 19, 2011
@Mange
Copy link

Mange commented Dec 9, 2011

Hmm, but with this it's impossible to map headers multiple times. We have to do it like this now:

def records_table(selector)
   records = some_way_to_get_data(selector)
   records.map_headers! { |header| header.downcase }

   # map, dammit
   table(records.hashes)
end

def users_table
   users = records_table('table.users')
   users.map_headers! { |header| header.sub(' (?)', '') }

   # map, dammit
   table(users.hashes)
end

The specific mappings here are fictional, but it's along the same lines. Basically, we have a common table type that has some decorative stuff in the text which we filter away. We then have specific tables that have some other columns that need scrubbing.

The deferred mappings should be stored in an array, perhaps? At least make it easier to do the mapping in case several mappings need to be chained. Any of these would suffice (although the last one is a bit ugly):

table.with_mapped_headers # => #<Table>
table.map_headers! { |header, previous_block| previous_block.call(header).downcase }

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants