Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Rounds any numeric value to any nearest multiple of the chosen step.
Returns value of the same type as the input argument.
For example:
require 'rounder'
17.round_to(10) # => 20
17.round_to(10.0) # => 20.0
9.47.floor_to(2.5) # => 7.5
101.ceil_to(25) # => 125
Add this line to your application's Gemfile:
gem 'rounder'
And then execute:
bundle
Or install the gem:
gem install rounder
Require the gem:
require 'rounder'
There are three methods added to all Numeric objects: #round_to
, #floor_to
, and #ceil_to
.
#round_to
rounds to the nearest multiple of the chosen step.
54.round_to(100) # => 100
1.4.round_to(3) # => 0
1.5.round_to(3) # => 3
1.6.round_to(3) # => 3
-8.round_to(3) # => -9
#floor_to
rounds down to a multiple of the chosen step.
299.floor_to(100) # => 200
1.81.floor_to(0.5) # => 1.5
60.floor_to(15) # => 60
-8.floor_to(3) # => -9
#ceil_to
rounds up to a multiple of the chosen step.
201.ceil_to(100) # => 300
1.71.ceil_to(0.5) # => 2.0
60.ceil_to(15) # => 60
-8.ceil_to(3) # => -6
Returned value type depends on the argument type.
21.round_to(10) # => 20
21.round_to(10.0) # => 20.0
21.0.round_to(10) # => 20
21.0.round_to(10.0) # => 20.0
If you provide zero as an argument, Rounder returns unaltered value.
21.round_to(0) # => 21
21.round_to(0.0) # => 21.0
If negative step is provided, Rounder will use it absolute value
4.round_to(2) # => 4
4.round_to(-2) # => 4
RoundTo uses BigDecimal, so calculations are fairly precise
2.round_to(0.0000000006) # => 1.9999999998
After checking out the repo, run bundle install
to install dependencies. Then, run rspec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Bug Reports and Pull Requests are welcome on GitHub Project page.
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Please read the CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Rounder project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the Code of Conduct.
FAQs
Unknown package
We found that rounder 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.