si 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +33 -0
- data/.gitignore +0 -1
- data/Gemfile +3 -0
- data/Gemfile.lock +23 -0
- data/README.md +6 -4
- data/lib/si/module.rb +3 -3
- data/lib/si/patch.rb +9 -11
- data/lib/si/version.rb +1 -1
- metadata +13 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e3d6c6cb24a8ed364c310019d4ad39af6f6bdc0c9ffeba7915854ef72a3de125
|
4
|
+
data.tar.gz: e67d999cd37a2f6d2cfb0c05994bb43d447e18bbc0e3aa9f0ee953f026772007
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c379c44a26d41a4d9e80448f6e9ced1b24723b9bb7b9300b2a71ec244c97c7fe98ea428e607c395d5940ea7b5a70f6b96a81cc0e0f770aa743c46b7c78fbe94a
|
7
|
+
data.tar.gz: d447b4d285805e5947d2f03caec9764f6547aebaa1b7feeacbe2f416a954e32f30559a9d8a55867a9aa3559c6f0ff318561ec742ff6d24e60f6054d5d483f177
|
@@ -0,0 +1,33 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
pull_request:
|
7
|
+
branches: [master]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby: ['2.6', '2.7', '3.0', '3.1', '3.2']
|
16
|
+
|
17
|
+
steps:
|
18
|
+
- uses: actions/checkout@v3
|
19
|
+
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
24
|
+
bundler-cache: true
|
25
|
+
|
26
|
+
- name: Update the RubyGems system software
|
27
|
+
run: gem update --system
|
28
|
+
|
29
|
+
- name: Update Bundler
|
30
|
+
run: bundle update --bundler
|
31
|
+
|
32
|
+
- name: Install dependencies
|
33
|
+
run: bundle install
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
si (0.1.4)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
power_assert (2.0.3)
|
10
|
+
rake (13.0.6)
|
11
|
+
test-unit (3.6.1)
|
12
|
+
power_assert
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
rake (~> 13.0, >= 13.0.6)
|
19
|
+
si!
|
20
|
+
test-unit (~> 3.6, >= 3.6.1)
|
21
|
+
|
22
|
+
BUNDLED WITH
|
23
|
+
2.4.10
|
data/README.md
CHANGED
@@ -45,10 +45,12 @@ require 'si'
|
|
45
45
|
|
46
46
|
#### Options
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
| Option | Default | Description |
|
49
|
+
|------------|---------|-----------------------------------------------------------------------------------------------------------|
|
50
|
+
| `:length` | 3 | Number of digits |
|
51
|
+
| `:base` | 1000 | For [binary prefix](http://en.wikipedia.org/wiki/Binary_prefix), set this to 1024 instead of default 1000 |
|
52
|
+
| `:min_exp` | -8 | Down to <strong>y</strong>octo |
|
53
|
+
| `:max_exp` | 8 | Up to <strong>Y</strong>otta |
|
52
54
|
|
53
55
|
```ruby
|
54
56
|
9876543210000.si(:length => 5) # '9.8765T'
|
data/lib/si/module.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module SI
|
2
2
|
class << self
|
3
3
|
def convert num, options = {}
|
4
|
-
options = { :length => options } if options.is_a?(
|
4
|
+
options = { :length => options } if options.is_a?(Numeric)
|
5
5
|
options = DEFAULT.merge(options)
|
6
6
|
length,
|
7
7
|
min_exp,
|
8
8
|
max_exp = options.values_at(:length, :min_exp, :max_exp)
|
9
9
|
raise ArgumentError.new("Invalid length") if length < 2
|
10
|
-
return num.is_a?(
|
10
|
+
return num.is_a?(Float) ? "0.#{'0' * (length - 1)}" : '0' if num == 0
|
11
11
|
|
12
12
|
base = options[:base].to_f
|
13
13
|
minus = num < 0 ? '-' : ''
|
@@ -18,7 +18,7 @@ module SI
|
|
18
18
|
if nump >= denom || exp == min_exp
|
19
19
|
val = nump / denom
|
20
20
|
val = SI.round val, [length - val.to_i.to_s.length, 0].max
|
21
|
-
val = val.to_i if exp == 0 && num.is_a?(
|
21
|
+
val = val.to_i if exp == 0 && !num.is_a?(Float)
|
22
22
|
val = val.to_s.ljust(length + 1, '0') if val.is_a?(Float)
|
23
23
|
|
24
24
|
return "#{minus}#{val}#{PREFIXES[exp]}"
|
data/lib/si/patch.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
|
2
|
-
include SI
|
3
|
-
end
|
1
|
+
original_verbosity = $VERBOSE
|
4
2
|
|
5
|
-
|
6
|
-
include SI
|
7
|
-
end
|
3
|
+
$VERBOSE = nil
|
8
4
|
|
9
|
-
|
10
|
-
|
11
|
-
end
|
5
|
+
['Float', 'Fixnum', 'Bignum', 'Rational', 'Integer'].each do |const|
|
6
|
+
next unless Object.const_defined?(const)
|
12
7
|
|
13
|
-
|
14
|
-
|
8
|
+
Object.const_get(const).class_eval do
|
9
|
+
include SI
|
10
|
+
end
|
15
11
|
end
|
12
|
+
|
13
|
+
$VERBOSE = original_verbosity
|
data/lib/si/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: si
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.2.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Junegunn Choi
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2023-08-26 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Formats a number with SI prefix
|
15
14
|
email:
|
@@ -18,8 +17,10 @@ executables: []
|
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
21
|
-
- .
|
20
|
+
- ".github/workflows/ruby.yml"
|
21
|
+
- ".gitignore"
|
22
22
|
- Gemfile
|
23
|
+
- Gemfile.lock
|
23
24
|
- LICENSE
|
24
25
|
- README.md
|
25
26
|
- Rakefile
|
@@ -33,28 +34,25 @@ files:
|
|
33
34
|
- test/test_si.rb
|
34
35
|
homepage: https://github.com/junegunn/si
|
35
36
|
licenses: []
|
36
|
-
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
37
39
|
rdoc_options: []
|
38
40
|
require_paths:
|
39
41
|
- lib
|
40
42
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
43
|
requirements:
|
43
|
-
- -
|
44
|
+
- - ">="
|
44
45
|
- !ruby/object:Gem::Version
|
45
46
|
version: '0'
|
46
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
48
|
requirements:
|
49
|
-
- -
|
49
|
+
- - ">="
|
50
50
|
- !ruby/object:Gem::Version
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
specification_version: 3
|
53
|
+
rubygems_version: 3.4.6
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
57
56
|
summary: Formats a number with SI prefix (metric prefix)
|
58
57
|
test_files:
|
59
58
|
- test/test_si.rb
|
60
|
-
has_rdoc:
|