{"id":16222918,"url":"https://github.com/michael/data_table","last_synced_at":"2026-03-11T21:03:29.178Z","repository":{"id":66264135,"uuid":"588420","full_name":"michael/data_table","owner":"michael","description":"In memory representation and manipulation of tabular data. Useful for powering all kinds of charts and exports. ","archived":false,"fork":false,"pushed_at":"2011-04-04T13:45:46.000Z","size":107,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-28T18:34:34.539Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/michael.png","metadata":{"files":{"readme":"README.rdoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-03-31T13:32:41.000Z","updated_at":"2023-06-03T16:37:05.000Z","dependencies_parsed_at":"2023-02-20T01:05:20.061Z","dependency_job_id":null,"html_url":"https://github.com/michael/data_table","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael%2Fdata_table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael%2Fdata_table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael%2Fdata_table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michael%2Fdata_table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michael","download_url":"https://codeload.github.com/michael/data_table/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243989109,"owners_count":20379648,"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":"2024-10-10T12:15:49.906Z","updated_at":"2026-03-11T21:03:24.158Z","avatar_url":"https://github.com/michael.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"= data_table\n\nIn memory representation and manipulation of tabular data. Useful for powering all kinds of charts and exports.\n\n\n  class OrderPosition\n\n    attr_accessor :articlenum\n    attr_accessor :name\n    attr_accessor :ordered\n    attr_accessor :group\n    attr_accessor :quantity\n    attr_accessor :price\n\n    def initialize(articlenum, name, group, ordered, quantity, price)\n      @articlenum = articlenum\n      @name = name\n      @group = group\n      @ordered = ordered\n      @quantity = quantity\n      @price = price\n    end\n\n  end\n\n  order_positions = [\n    OrderPosition.new \"23423424\", \"R2D1\", \"AA\", Date.new(2009, 10, 4), 1, 1000.0,\n    OrderPosition.new \"56456345\", \"R2D2\", \"AA\", Date.new(2009,  9, 4), 1,  100.0,\n    OrderPosition.new \"42342344\", \"R2D3\", \"AA\", Date.new(2009,  9, 4), 1,   10.0,\n    OrderPosition.new \"56757657\", \"R2D4\", \"BB\", Date.new(2009, 10, 4), 1,  200.0,\n    OrderPosition.new \"56678799\", \"R2D5\", \"BB\", Date.new(2009, 10, 4), 1,   20.0\n  ]\n\n\n  # ----------------------------------------\n  #           DataTable block API\n  # ----------------------------------------\n\n  # order_positions will be available as source inside the block\n\n  t = DataTable.new(order_positions) do\n\n    # Variant 1: implicit method lookup\n\n    column :articlenum,    \"Articlenum\"\n    column :name,          \"Product Name\"\n    column :ordered,       \"Datum\"\n    column :group,         \"Product Group\"\n\n    # Variant 2: explicit transformer function that yields an item of your collection\n\n    column :amount,        \"Amount\", lambda { |p| p.quantity*p.price }\n\n    # Variant 3: explicit row modification (see build_rows)\n\n    column(:doubled_price, \"Doubled Price\")\n    build_rows(source) do |row, p| # block can be omitted\n      row[:doubled_price] = p.price * 2\n    end\n\n  end\n\n\n  # ----------------------------------------\n  #      DataTable public method API\n  # ----------------------------------------\n\n  t = DataTable.new\n\n  # Variant 1: implicit method lookup\n\n  t.column :articlenum,    \"Articlenum\"\n  t.column :name,          \"Product Name\"\n  t.column :ordered,       \"Datum\"\n  t.column :group,         \"Product Group\"\n\n  # Variant 2: explicit transformer function that yields an item of your collection\n\n  t.column(:amount,        \"Amount\", lambda { |p| p.quantity*p.price })\n\n  # Variant 3: explicit row modification (see build_rows)\n\n  t.column(:doubled_price, \"Doubled Price\")\n  t.build_rows(order_positions) do |row, p| # block can be omitted\n    row[:doubled_price] = p.price * 2\n  end\n\n\n  # ----------------------------------------\n  #                Grouping\n  # ----------------------------------------\n\n  grouped_table = t.group_by(:ordered, {\n    :amount        =\u003e DataTable::Aggregators::SUM,\n    :doubled_price =\u003e DataTable::Aggregators::SUM\n  }, lambda { |x| \"#{x.year}-#{x.month}\" })\n\n\n  # ----------------------------------------\n  #                Exporting\n  # ----------------------------------------\n\n  grouped_table.to_csv # defaults to (:col_sep =\u003e \",\")\n\n\n== Note on Patches/Pull Requests\n \n* Fork the project.\n* Make your feature addition or bug fix.\n* Add tests for it. This is important so I don't break it in a\n  future version unintentionally.\n* Commit, do not mess with rakefile, version, or history.\n  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)\n* Send me a pull request. Bonus points for topic branches.\n\n== Copyright\n\nCopyright (c) 2010 Michael Aufreiter. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael%2Fdata_table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichael%2Fdata_table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichael%2Fdata_table/lists"}