short_scale 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/short_scale/version.rb +3 -0
- data/lib/short_scale.rb +7 -0
- data/short_scale.gemspec +25 -0
- metadata +101 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9c5ce2c81bf4c7ec35a1e4373515738ce646e830
|
|
4
|
+
data.tar.gz: 98e60a39fb421131c7e9f4c6c9b24c7dfec0ece3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 34bf990fd9968ec0e3a7544003ee62dc04103d07071ace51cdbddba014ff6460be81e34a5caa0f2c4031d456051c85e6ad61ee38debce9e3fd3b93f1179f109b
|
|
7
|
+
data.tar.gz: 18a277ae8063ee5a2b57ddee2412b74ebc3245fc28bb8ea804f8f5338d983d65cc390260a21aecf57c2c87b9cb40a50c2e083a82d0683c681591d352eb0d1fe9
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Érik Escobedo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# ShortScale
|
|
2
|
+
|
|
3
|
+
ShortScale provides a `Prettifier` class capable of display numbers in a
|
|
4
|
+
"Short Scale" format (https://en.wikipedia.org/wiki/Long_and_short_scales).
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'short_scale'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install short_scale
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
require 'short_scale'
|
|
26
|
+
|
|
27
|
+
# If no configuration is provided, it will use 'M' for 10^6, 'B' for 10^9 and 'T' for
|
|
28
|
+
# 10^12 and bigger numbers.
|
|
29
|
+
prettifier = ShortScale::Prettifier.new
|
|
30
|
+
|
|
31
|
+
prettifier.prettify(1_000_000) #=> '1M'
|
|
32
|
+
prettifier.prettify(512.5) #=> '512.5'
|
|
33
|
+
prettifier.prettify(2_345_000.123) #=> '2.3M'
|
|
34
|
+
prettifier.prettify(123_456_789_123) #=> '123.4B'
|
|
35
|
+
prettifier.prettify(9_123_456_789_123) #=> '9.1T'
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# You can also provide a set of tiers in the following format
|
|
39
|
+
prettifier = ShortScale::Prettifier.new(tiers: {
|
|
40
|
+
0 => ' units',
|
|
41
|
+
3 => ' thousands',
|
|
42
|
+
6 => ' millions',
|
|
43
|
+
9 => ' billions'
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
prettifier.prettify(1_000_000) #=> '1 millions' (no support for singular/plural inflections)
|
|
47
|
+
prettifier.prettify(5125.4) #=> '5.1 thousands'
|
|
48
|
+
prettifier.prettify(345.123) #=> '345.1 units'
|
|
49
|
+
prettifier.prettify(123_456_789_123) #=> '123.4 billions'
|
|
50
|
+
prettifier.prettify(9_123_456_789_123) #=> '9123.4 billions' (since trillions tier was not provided)
|
|
51
|
+
|
|
52
|
+
# It also works with bases different than 10
|
|
53
|
+
prettifier = ShortScale::Prettifier.new(base: 2, tiers: {
|
|
54
|
+
0 => 'B',
|
|
55
|
+
10 => 'KB',
|
|
56
|
+
20 => 'MB',
|
|
57
|
+
30 => 'GB',
|
|
58
|
+
40 => 'TB'
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
prettifier.prettify(1023) #=> '1023B'
|
|
62
|
+
prettifier.prettify(1024) #=> '1KB'
|
|
63
|
+
prettifier.prettify(1048064) #=> '1023.5KB'
|
|
64
|
+
prettifier.prettify(1048576) #=> '1MB'
|
|
65
|
+
prettifier.prettify(9_123_456_789_123) #=> '8TB'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
71
|
+
|
|
72
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
73
|
+
|
|
74
|
+
## Contributing
|
|
75
|
+
|
|
76
|
+
1. Fork it ( https://github.com/erik-escobedo/short_scale/fork )
|
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
80
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "short_scale"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/short_scale.rb
ADDED
data/short_scale.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'short_scale/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "short_scale"
|
|
8
|
+
spec.version = ShortScale::VERSION
|
|
9
|
+
spec.authors = ["Érik Escobedo"]
|
|
10
|
+
spec.email = ["erik@codigojade.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Prettify big numbers using Short Scale format.}
|
|
13
|
+
spec.description = %q{Prettify big numbers using Short Scale format.}
|
|
14
|
+
spec.homepage = "http://github.com/erik-escobedo/short_scale"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
spec.bindir = "exe"
|
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
|
+
spec.require_paths = Dir["lib/**/*.rb"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: short_scale
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.3
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- "Érik Escobedo"
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-11-17 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.9'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.9'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.3'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.3'
|
|
55
|
+
description: Prettify big numbers using Short Scale format.
|
|
56
|
+
email:
|
|
57
|
+
- erik@codigojade.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".travis.yml"
|
|
64
|
+
- Gemfile
|
|
65
|
+
- LICENSE.txt
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- bin/console
|
|
69
|
+
- bin/setup
|
|
70
|
+
- lib/short_scale.rb
|
|
71
|
+
- lib/short_scale/version.rb
|
|
72
|
+
- short_scale.gemspec
|
|
73
|
+
homepage: http://github.com/erik-escobedo/short_scale
|
|
74
|
+
licenses:
|
|
75
|
+
- MIT
|
|
76
|
+
metadata: {}
|
|
77
|
+
post_install_message:
|
|
78
|
+
rdoc_options: []
|
|
79
|
+
require_paths:
|
|
80
|
+
- lib/short_scale/formatter.rb
|
|
81
|
+
- lib/short_scale/prettifier.rb
|
|
82
|
+
- lib/short_scale/tier_calculator.rb
|
|
83
|
+
- lib/short_scale/version.rb
|
|
84
|
+
- lib/short_scale.rb
|
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
|
+
requirements:
|
|
92
|
+
- - ">="
|
|
93
|
+
- !ruby/object:Gem::Version
|
|
94
|
+
version: '0'
|
|
95
|
+
requirements: []
|
|
96
|
+
rubyforge_project:
|
|
97
|
+
rubygems_version: 2.4.5
|
|
98
|
+
signing_key:
|
|
99
|
+
specification_version: 4
|
|
100
|
+
summary: Prettify big numbers using Short Scale format.
|
|
101
|
+
test_files: []
|