{"id":21570386,"url":"https://github.com/arirusso/analog","last_synced_at":"2025-10-28T08:50:31.645Z","repository":{"id":15720822,"uuid":"18458948","full_name":"arirusso/analog","owner":"arirusso","description":"A Ruby helper for scaling numbers","archived":false,"fork":false,"pushed_at":"2022-08-26T19:18:15.000Z","size":27,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-24T12:56:20.523Z","etag":null,"topics":["math","numbers","range","ranges","ruby","ruby-helpers","scale","scaling-numbers"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arirusso.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":"2014-04-05T03:11:20.000Z","updated_at":"2020-07-07T17:58:33.000Z","dependencies_parsed_at":"2022-08-25T12:01:03.389Z","dependency_job_id":null,"html_url":"https://github.com/arirusso/analog","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/arirusso%2Fanalog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arirusso%2Fanalog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arirusso%2Fanalog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arirusso%2Fanalog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arirusso","download_url":"https://codeload.github.com/arirusso/analog/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248232685,"owners_count":21069489,"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":["math","numbers","range","ranges","ruby","ruby-helpers","scale","scaling-numbers"],"created_at":"2024-11-24T11:12:29.249Z","updated_at":"2025-10-28T08:50:26.626Z","avatar_url":"https://github.com/arirusso.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Analog\n\nA Ruby helper for scaling numbers\n\n#### Background\n\nProvides a quick way to scale a number from one range or set to another.\n\nA simple example is:\n\nYou'd like to plot a point on a 500px graph using a data that lies in the 0..1 range.\n\n```ruby\nScale.transform(0.5).from(0..1).to(0..500)\n=\u003e 250\n```\n\nIt's commonly useful for preparing data to be consumed by generalized APIs and communication protocols.\n\nPersonally, I've used it in graphics, audio and for converting music data between OSC and MIDI.\n\n#### Usage\n\n```ruby\nrequire \"scale\"\n```\n\nThis example will scale a number down by 1/10th\n\n```ruby\nScale.transform(22).from(0..150).to(0..15)\n=\u003e 2\n\n```\n\nOutput a float by using a float in the destination range\n\n\n```ruby\nScale.transform(22).from(0..150).to(0..15.0)\n=\u003e 2.2\n\n```\n\nUse Arrays and Sets\n```ruby\nScale.transform(0.40).from(0..1).to([0, 2, 4, 8, 12, 16, 32, 64, 128, 512])\n=\u003e 8\n\nScale.transform(8).from(Set.new([0, 2, 4, 8, 16, 64])).to(0..10)\n=\u003e 6\n```\n\nSee the [examples](https://github.com/arirusso/analog/tree/master/examples) for more\n\n###### Core Extension\n\nThere is a Numeric extension that you can optionally include.\n\n```ruby\nrequire \"scale/core_ext\"\n\n0.40.scaled_from(0..1).to([0, 2, 4, 8, 12, 16, 32, 64, 128, 512])\n=\u003e 8\n```\n\nSee the [core_ext example](https://github.com/arirusso/analog/blob/master/examples/core_ext.rb) for more examples.\n\n#### Installation\n\n    gem install analog\n\nor with Bundler\n\n    gem \"analog\"\n\n#### License\n\nLicensed under Apache 2.0, See the file LICENSE\n\nCopyright (c) 2014-2017 [Ari Russo](http://arirusso.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farirusso%2Fanalog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farirusso%2Fanalog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farirusso%2Fanalog/lists"}