Code Monkey home page Code Monkey logo

Comments (5)

kou avatar kou commented on July 2, 2024

Can you show a runnable Ruby script that reproduces this case?

from csv.

troycroz avatar troycroz commented on July 2, 2024

@kou

raw_csv_data = "col_header_1, col_header_2\nval_1, val_2\n"

# This should raise and break execution flow if it is called
custom_converter = lambda { |header_val| raise 'break'}

broken_converters = [:symbol, custom_converter]
working_converters = [custom_converter, :symbol]

# custom_converter not called (as seen via lack of raise)
# symbol converter happens first, and short-circuits subsequent converters
CSV.parse(raw_csv_data, :headers => true, :header_converters => broken_converters)
# custom_converter called (as seen via raise)
CSV.parse(raw_csv_data, :headers => true, :header_converters => working_converters)

from csv.

kou avatar kou commented on July 2, 2024

Thanks.

In your use case (symbol -> squeeze("_") -> symbol), you should use :headers_converters =>[squeeze_converter, :symbol]. Because you can't call squeeze for Symbol. You can't put the squeeze converter after symbol converter.

:headers_converters => [:symbol, squeeze_converter] is a your application bug.

The current behavior is reasonable for this use case.
Do you have any other use case?

from csv.

troycroz avatar troycroz commented on July 2, 2024

@kou regardless of what my converter does, if its after the :symbol converted, it would never execute.

The docs for the CSV initializer method don't state this, and it seems unreasonable that a dev should have to dig way deep into the source code to discover that the header_converter loop early-exits after anything returns a symbol.

It seems like that early-exit is a bug, or, at the very least, needs to be better documented in the initializer docs.

from csv.

kou avatar kou commented on July 2, 2024

Can you try sending a pull request to improve the current document?

from csv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.