numeric-filesize 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7b662f197b9f908a1118c8707cfd9a2f86686e330a40cbaf809cab46570526b2
4
+ data.tar.gz: 88ea60c8d803fa79033d8b365f7dfdea9532838b22cff4af2862c4121fe4a795
5
+ SHA512:
6
+ metadata.gz: 5739d7efe68528591de68d2920b4cfc7f9133c3f12cfd5e287a4bbc944063091db5cb3fe53a287ad95d4daa1615284893629797ce9dbbfffde3ccd7d87fb397b
7
+ data.tar.gz: 9e3e405e2ca65505368d326d4ec427062d12872e20857aae34f93b6653a5f2ea7aa448caad2c436d591b336062a21adc979ff8e0158dd8d0ee48ff34475eabcc
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [1.0.0] - 2023-08-15
2
+
3
+ - Initial release.
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nnbnh@protonmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in trash.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rubocop', '~> 1.21'
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 NNB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 NNB
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,65 @@
1
+ <img width="100%" src="https://capsule-render.vercel.app/api?type=waving&section=header&color=DC2626&fontColor=FEF2F2&height=256&text=numeric-filesize&desc=Cheap%20and%20convenient%20way%20to%20add%20filesize%20to%20Ruby&fontAlignY=40" />
2
+
3
+ ## 💡 About
4
+
5
+ This adds methods to numeric class to returns bytes from filesize and reverse.
6
+
7
+ ## 📥 Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ ```sh
12
+ bundle add numeric-filesize
13
+ ```
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ ```sh
18
+ gem install numeric-filesize
19
+ ```
20
+
21
+ ## ⌨️ Usage
22
+
23
+ In Ruby do:
24
+
25
+ ```rb
26
+ require 'numeric/filesize'
27
+ ```
28
+
29
+ Enjoy filesize in Ruby:
30
+
31
+ ```rb
32
+ 1.b #=> 1
33
+ 1.kb #=> 1000
34
+ 1.mb #=> 1000_000
35
+ 1.gb #=> 1000_000_000
36
+ 1.tb #=> 1000_000_000_000
37
+ 1.pb #=> 1000_000_000_000_000
38
+ 1.eb #=> 1000_000_000_000_000_000
39
+ 1.kib #=> 1024
40
+ 1.mib #=> 1048_576
41
+ 1.gib #=> 1073_741_824
42
+ 1.tib #=> 1099_511_627_776
43
+ 1.pib #=> 1125_899_906_842_624
44
+ 1.eib #=> 1152_921_504_606_846_976
45
+
46
+ 1.to_b #=> 1
47
+ 1000.to_kb #=> 1
48
+ 1000_000.to_mb #=> 1
49
+ 1000_000_000.to_gb #=> 1
50
+ 1000_000_000_000.to_tb #=> 1
51
+ 1000_000_000_000_000.to_pb #=> 1
52
+ 1000_000_000_000_000_000.to_eb #=> 1
53
+ 1024.to_kib #=> 1
54
+ 1048_576.to_mib #=> 1
55
+ 1073_741_824.to_gib #=> 1
56
+ 1099_511_627_776.to_tib #=> 1
57
+ 1125_899_906_842_624.to_pib #=> 1
58
+ 1152_921_504_606_846_976.to_eib #=> 1
59
+ ```
60
+
61
+ ## 💌 Credits
62
+
63
+ - [**Nushell**](https://www.nushell.sh/book/types_of_data.html#file-sizes) by [it's contributors](https://github.com/nushell/nushell/graphs/contributors)
64
+
65
+ <a href="https://codeberg.org/NNB"><img width="100%" src="https://capsule-render.vercel.app/api?type=waving&section=footer&color=DC2626&fontColor=FEF2F2&height=128&desc=Made%20with%20%26lt;3%20by%20NNB&descAlignY=80" /></a>
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rubocop/rake_task'
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Numeric
4
+ # Returns `self` bytes from bytes.
5
+ def b
6
+ round
7
+ end
8
+
9
+ # Returns `self` bytes.
10
+ def to_b
11
+ round
12
+ end
13
+
14
+ # Returns `self` bytes from kilobytes.
15
+ def kb
16
+ (self * 1000).round
17
+ end
18
+
19
+ # Returns `self` kilobytes.
20
+ def to_kb
21
+ (self / 1000).round
22
+ end
23
+
24
+ # Returns `self` bytes from megabytes.
25
+ def mb
26
+ (self * 1000**2).round
27
+ end
28
+
29
+ # Returns `self` megabytes.
30
+ def to_mb
31
+ (self / 1000**2).round
32
+ end
33
+
34
+ # Returns `self` bytes from gigabytes.
35
+ def gb
36
+ (self * 1000**3).round
37
+ end
38
+
39
+ # Returns `self` gigabytes.
40
+ def to_gb
41
+ (self / 1000**3).round
42
+ end
43
+
44
+ # Returns `self` bytes from terabytes.
45
+ def tb
46
+ (self * 1000**4).round
47
+ end
48
+
49
+ # Returns `self` terabytes.
50
+ def to_tb
51
+ (self / 1000**4).round
52
+ end
53
+
54
+ # Returns `self` bytes from petabytes.
55
+ def pb
56
+ (self * 1000**5).round
57
+ end
58
+
59
+ # Returns `self` petabytes.
60
+ def to_pb
61
+ (self / 1000**5).round
62
+ end
63
+
64
+ # Returns `self` bytes from exabytes.
65
+ def eb
66
+ (self * 1000**6).round
67
+ end
68
+
69
+ # Returns `self` exabytes.
70
+ def to_eb
71
+ (self / 1000**6).round
72
+ end
73
+
74
+ # Returns `self` bytes from kibibytes.
75
+ def kib
76
+ (self * 1024).round
77
+ end
78
+
79
+ # Returns `self` kibibytes.
80
+ def to_kib
81
+ (self / 1024).round
82
+ end
83
+
84
+ # Returns `self` bytes from mebibytes.
85
+ def mib
86
+ (self * 1024**2).round
87
+ end
88
+
89
+ # Returns `self` mebibytes.
90
+ def to_mib
91
+ (self / 1024**2).round
92
+ end
93
+
94
+ # Returns `self` bytes from gibibytes.
95
+ def gib
96
+ (self * 1024**3).round
97
+ end
98
+
99
+ # Returns `self` gibibytes.
100
+ def to_gib
101
+ (self / 1024**3).round
102
+ end
103
+
104
+ # Returns `self` bytes from tebibytes.
105
+ def tib
106
+ (self * 1024**4).round
107
+ end
108
+
109
+ # Returns `self` tebibytes.
110
+ def to_tib
111
+ (self / 1024**4).round
112
+ end
113
+
114
+ # Returns `self` bytes from pebibytes.
115
+ def pib
116
+ (self * 1024**5).round
117
+ end
118
+
119
+ # Returns `self` pebibytes.
120
+ def to_pib
121
+ (self / 1024**5).round
122
+ end
123
+
124
+ # Returns `self` bytes from exbibyte.
125
+ def eib
126
+ (self * 1024**6).round
127
+ end
128
+
129
+ # Returns `self` exbibyte.
130
+ def to_eib
131
+ (self / 1024**6).round
132
+ end
133
+ end
@@ -0,0 +1,79 @@
1
+ class Numeric
2
+ # Returns `self` bytes from bytes.
3
+ def b: () -> Integer
4
+
5
+ # Returns `self` bytes.
6
+ def to_b: () -> Integer
7
+
8
+ # Returns `self` bytes from kilobytes.
9
+ def kb: () -> Integer
10
+
11
+ # Returns `self` kilobytes.
12
+ def to_kb: () -> Integer
13
+
14
+ # Returns `self` bytes from megabytes.
15
+ def mb: () -> Integer
16
+
17
+ # Returns `self` megabytes.
18
+ def to_mb: () -> Integer
19
+
20
+ # Returns `self` bytes from gigabytes.
21
+ def gb: () -> Integer
22
+
23
+ # Returns `self` gigabytes.
24
+ def to_gb: () -> Integer
25
+
26
+ # Returns `self` bytes from terabytes.
27
+ def tb: () -> Integer
28
+
29
+ # Returns `self` terabytes.
30
+ def to_tb: () -> Integer
31
+
32
+ # Returns `self` bytes from petabytes.
33
+ def pb: () -> Integer
34
+
35
+ # Returns `self` petabytes.
36
+ def to_pb: () -> Integer
37
+
38
+ # Returns `self` bytes from exabytes.
39
+ def eb: () -> Integer
40
+
41
+ # Returns `self` exabytes.
42
+ def to_eb: () -> Integer
43
+
44
+ # Returns `self` bytes from kibibytes.
45
+ def kib: () -> Integer
46
+
47
+ # Returns `self` kibibytes.
48
+ def to_kib: () -> Integer
49
+
50
+ # Returns `self` bytes from mebibytes.
51
+ def mib: () -> Integer
52
+
53
+ # Returns `self` mebibytes.
54
+ def to_mib: () -> Integer
55
+
56
+ # Returns `self` bytes from gibibytes.
57
+ def gib: () -> Integer
58
+
59
+ # Returns `self` gibibytes.
60
+ def to_gib: () -> Integer
61
+
62
+ # Returns `self` bytes from tebibytes.
63
+ def tib: () -> Integer
64
+
65
+ # Returns `self` tebibytes.
66
+ def to_tib: () -> Integer
67
+
68
+ # Returns `self` bytes from pebibytes.
69
+ def pib: () -> Integer
70
+
71
+ # Returns `self` pebibytes.
72
+ def to_pib: () -> Integer
73
+
74
+ # Returns `self` bytes from exbibyte.
75
+ def eib: () -> Integer
76
+
77
+ # Returns `self` exbibyte.
78
+ def to_eib: () -> Integer
79
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: numeric-filesize
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - NNB
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This adds methods to numeric class to returns bytes from filesize and
14
+ reverse.
15
+ email:
16
+ - nnbnh@protonmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.md
21
+ - CHANGELOG.md
22
+ - LICENSE.txt
23
+ files:
24
+ - ".rubocop.yml"
25
+ - CHANGELOG.md
26
+ - CODE_OF_CONDUCT.md
27
+ - Gemfile
28
+ - LICENSE
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - lib/numeric/filesize.rb
33
+ - sig/numeric/filesize.rbs
34
+ homepage: https://codeberg.org/NNB/numeric-filesize.rb
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ homepage_uri: https://codeberg.org/NNB/numeric-filesize.rb
39
+ source_code_uri: https://codeberg.org/NNB/numeric-filesize.rb
40
+ changelog_uri: https://codeberg.org/NNB/numeric-filesize.rb/src/branch/main/CHANGELOG.md
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '3.0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubygems_version: 3.4.10
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Cheap and convenient way to add filesize to Ruby.
60
+ test_files: []