{"id":15543733,"url":"https://github.com/amiel/bitmask","last_synced_at":"2025-04-23T17:28:59.125Z","repository":{"id":3159496,"uuid":"4189951","full_name":"amiel/bitmask","owner":"amiel","description":"Bitmask represents a set of boolean values as an Integer","archived":false,"fork":false,"pushed_at":"2022-06-07T19:58:51.000Z","size":15,"stargazers_count":6,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-03T12:33:03.539Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/amiel/bitmask","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/amiel.png","metadata":{"files":{"readme":"README.md","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":"2012-05-01T05:44:12.000Z","updated_at":"2022-06-06T20:39:57.000Z","dependencies_parsed_at":"2022-08-19T11:42:28.932Z","dependency_job_id":null,"html_url":"https://github.com/amiel/bitmask","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiel%2Fbitmask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiel%2Fbitmask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiel%2Fbitmask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amiel%2Fbitmask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amiel","download_url":"https://codeload.github.com/amiel/bitmask/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250479939,"owners_count":21437463,"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-02T12:28:12.119Z","updated_at":"2025-04-23T17:28:59.106Z","avatar_url":"https://github.com/amiel.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bitmask\n\nBitmask represents a set of boolean values as an Integer.\n\nThis bitmask gem was extracted from [amiel/has_bitmask_attributes](https://github.com/amiel/has_bitmask_attributes)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'bitmask'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install bitmask\n\n## Usage\n\n\nExamples:\n\n```ruby\n  masks = {\n            :cat  =\u003e 0b0001,\n            :dog  =\u003e 0b0010,\n            :fish =\u003e 0b0100,\n          }\n\n  bitmask = Bitmask.new(masks, {:cat =\u003e true})\n  bitmask.to_i            # =\u003e 1\n  bitmask.get :cat        # =\u003e true\n  bitmask.get :dog        # =\u003e false\n  bitmask.set :dog, true\n  bitmask.get :dog        # =\u003e true\n  bitmask.to_i            # =\u003e 3\n  bitmask.to_h            # =\u003e { :cat =\u003e true, :dog =\u003e true, :fish =\u003e false }\n\n  bitmask = Bitmask.new(masks, 0b101)\n  bitmask.to_h            # =\u003e { :cat =\u003e true, :dog =\u003e false, :fish =\u003e true }\n  bitmask.to_i            # =\u003e 5\n  bitmask.to_i.to_s(2)    # =\u003e \"101\"\n\n  Bitmask.new(masks, 5) == Bitmask.new(masks, { :cat =\u003e true, :dog =\u003e false, :fish =\u003e true }) # =\u003e true\n\n  # Least Significant Bit - LSB\n  bitmask = Bitmask.new(masks, {:cat =\u003e true, :fish =\u003e true})\n  bitmask.lsb # =\u003e 1\n  bitmask.lsb.to_s(2) # =\u003e \"1\"\n  Bitmask.new(masks, bitmask.lsb).to_a # =\u003e [:cat]\n\n  # Most Significant Bit - MSB\n  bitmask = Bitmask.new(masks, 0b101)\n  bitmask.msb # =\u003e 4\n  bitmask.msb.to_s(2) # =\u003e \"100\"\n  Bitmask.new(masks, bitmask.msb).to_a # =\u003e [:fish]\n```\n\n### Chaining\n\n```ruby\n  masks = {\n            :cat  =\u003e 0b0001,\n            :dog  =\u003e 0b0010,\n            :fish =\u003e 0b0100,\n          }\n  bitmask = Bitmask.new(masks, {:cat =\u003e true})\n  bitmask.to_i.to_s(2)    # =\u003e \"1\"\n  bitmask.set(:dog, true).set(:cat, false).set(:fish, true)\n  bitmask.to_i.to_s(2)    # =\u003e \"110\"\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Added some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famiel%2Fbitmask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famiel%2Fbitmask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famiel%2Fbitmask/lists"}