{"id":24698558,"url":"https://github.com/faradayio/typedcsv-ruby","last_synced_at":"2025-03-22T03:41:56.127Z","repository":{"id":59158409,"uuid":"102620750","full_name":"faradayio/typedcsv-ruby","owner":"faradayio","description":"The obvious thing: put types in CSV headers. Ruby lib.","archived":false,"fork":false,"pushed_at":"2017-09-06T18:25:29.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-02-28T17:51:41.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faradayio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-06T14:44:58.000Z","updated_at":"2017-09-06T15:32:59.000Z","dependencies_parsed_at":"2022-09-13T20:10:50.662Z","dependency_job_id":null,"html_url":"https://github.com/faradayio/typedcsv-ruby","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faradayio%2Ftypedcsv-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faradayio%2Ftypedcsv-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faradayio%2Ftypedcsv-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faradayio%2Ftypedcsv-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faradayio","download_url":"https://codeload.github.com/faradayio/typedcsv-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244902936,"owners_count":20529114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-27T04:29:19.024Z","updated_at":"2025-03-22T03:41:56.104Z","avatar_url":"https://github.com/faradayio.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typedcsv\n\nHere's your standard untyped CSV:\n\n```\nname,income,created_at,tags,great\nSeamus,12301.2,2012-02-21,\"red,blue\",true\n```\n\nNow, you and I know that `12301.2` is a number and `2012-02-21` is a date and `\"red,blue\"` is a list... so let's just write that into the headers:\n\n```\nname,income:number,created_at:date,tags:list,great:boolean\nSeamus,12301.2,2012-02-21,\"red,blue\",true\n```\n\nNow let's parse it:\n\n```\nTypedcsv.foreach('file.csv', headers: true) do |row|\n  row['income']     # will be a Float\n  row['created_at'] # will be a Date\n  row['tags']       # will be an Array\n  row['great']      # will be TrueClass or FalseClass\nend\n```\n\nThis gem provides `Typedcsv.foreach()`, which takes exactly the same arguments as [ruby stdlib `CSV.foreach`](https://ruby-doc.org/stdlib-2.4.1/libdoc/csv/rdoc/CSV.html#method-c-foreach).\n\n## Types\n\n* text (default)\n* number\n* list (must be comma-separated and therefore quoted)\n* date (must be ISO8601)\n* time (must be ISO8601)\n* boolean (recognizes \"true\" or \"false\")\n\n## Benchmarks\n\nIt's about 10x slower than ruby's stdlib `CSV.foreach`:\n\n```\ncd benchmark \u0026\u0026 ruby benchmark.rb\n[...]\nCSV.foreach - array mode\n                          2.503  (± 0.0%) i/s -     13.000  in   5.197588s\nTypedcsv.foreach - array mode\n                          0.253  (± 0.0%) i/s -      2.000  in   7.892107s\nCSV.foreach - hash mode\n                          1.830  (± 0.0%) i/s -     10.000  in   5.466998s\nTypedcsv.foreach - hash mode\n                          0.226  (± 0.0%) i/s -      2.000  in   8.867616s\n```\n\n## Sponsor\n\n\u003cp\u003e\u003ca href=\"https://www.faraday.io\"\u003e\u003cimg src=\"https://s3.amazonaws.com/faraday-assets/files/img/logo.svg\" alt=\"Faraday logo\"/\u003e\u003c/a\u003e\u003c/p\u003e\n\nWe use [`typedcsv`](https://github.com/faradayio/typedcsv) for [B2C customer intelligence at Faraday](https://www.faraday.io).\n\n## Copyright\n\nCopyright 2017 Faraday\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaradayio%2Ftypedcsv-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaradayio%2Ftypedcsv-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaradayio%2Ftypedcsv-ruby/lists"}