
Security News
Nx npm Packages Compromised in Supply Chain Attack Weaponizing AI CLI Tools
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
RankingDistance is a Ruby gem that provides a simple and efficient way to compute the distance between two rankings. Rankings are arrays of elements, and the distance is a positive number that is small when the rankings are similar and bigger when they are not.
Unlike other edit distances, such as the Levenshtein distance, RankDistance weights more the insertions at the front of the rankings and gives less weight to insertions at the back of the rankings. This makes the distance computed by RankDistance more reflective of the percived similarity between the rankings.
Add this line to your application's Gemfile:
gem 'ranking_distance'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install ranking_distance
3 Methods are available:
RankingDistance.absolute_distance(arr1, arr2)
Computes the absolute distance between two arrays.
The absolute distance is computed as follows:
- if the two arrays are equal, the distance is 0
- if the two arrays are different, the distance is the number of swaps and insertions needed to transform one array into the other
- Each swap cost is dependent on the distance between the two swapped elements
- Each insertion cost is dependent on the position of the inserted element (inserting at the end is cheaper than inserting at the start)
The absolute distance is thus always a positive integer.
RankingDistance.relative_distance(arr1, arr2)
Computes the relative distance between two arrays.
The relative distance is computed by dividing the absolute distance by the maximum possible distance between the two arrays.
This means that the relative distance is always a float between 0 and 1.
0 if the two arrays are equal, 1 if the two arrays are built with completely different elements.
RankingDistance.relative_proximity(arr1, arr2)
Computes the relative proximity between two arrays.
The relative proximity is computed by substracting the relative distance from 1.
This means that the relative proximity is always a float between 0 and 1.
1 if the two arrays are equal, 0 if the two arrays are built with completely different elements.
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/almathie/ranking_distance.
FAQs
Unknown package
We found that ranking_distance demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.