human_file_size 0.1.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: c8c762080085db0816483fce60f174eaddb63803e8c280574bfeea9feeda0acf
4
+ data.tar.gz: f08ca29cc3b2fffbf1e35f6622c7e3e7bab266cf5ecf01280c6094fc37f26be3
5
+ SHA512:
6
+ metadata.gz: 55bfb51d38a30c359d8755a449feef2b9d8cdbf232901a5498cc94e55fe5c1de93a53306d15c8e689d02d11a4dc334ccc8f0608a4300ed024eae9b1625292456
7
+ data.tar.gz: 19809421d18313b9a06c54a406d3ca2358497a5f372050b20dd6615521a5809a3be224df1b43e014f425749b796e318ff975e63e7869fd00bfd5ad4ef76f9fec
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="jdk" jdkName="ruby-3.3.8-p144" jdkType="RUBY_SDK" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.6.8, ruby-3.3.8-p144) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.25.5, ruby-3.3.8-p144) [gem]" level="application" />
16
+ </component>
17
+ </module>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/human_file_size.iml" filepath="$PROJECT_DIR$/.idea/human_file_size.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'minitest'
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ human_file_size (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ minitest (5.25.5)
10
+
11
+ PLATFORMS
12
+ x64-mingw-ucrt
13
+
14
+ DEPENDENCIES
15
+ human_file_size!
16
+ minitest
17
+
18
+ BUNDLED WITH
19
+ 2.6.8
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Andrii Stavskyi
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Human File Size
2
+ A simple Gem for formatting file sizes into a human-readable format.
3
+
4
+ ## Installation
5
+ Add this line to your application's `Gemfile`:
6
+
7
+ ```ruby
8
+ gem 'human_file_size'
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ bundle install
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```bash
18
+ gem install human_file_size
19
+ ```
20
+
21
+ ## Usage
22
+ ```ruby
23
+ require 'human_file_size'
24
+
25
+ HumanFileSize.format(100) # => "100.00 B"
26
+ HumanFileSize.format(1024) # => "1.00 KB"
27
+ HumanFileSize.format(1536) # => "1.50 KB"
28
+ HumanFileSize.format(1048576) # => "1.00 MB"
29
+ HumanFileSize.format(2621440, precision: 1) # => "2.5 MB"
30
+ HumanFileSize.format(1572864576) # => "1.50 GB"
31
+ ```
32
+
33
+ ## License
34
+ This Gem is distributed under the MIT License. See the [LICENSE.txt](LICENSE) fire for details
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/human_file_size/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "human_file_size"
7
+ spec.version = HumanFileSize::VERSION
8
+ spec.authors = ["Andrii Stavskyi"]
9
+ spec.email = ["an.stawski@outlook.com"]
10
+
11
+ spec.summary = "Formats file sizes into a human-readable format."
12
+ spec.description = "Accepts a file size in bytes and returns a string with the appropriate prefix (e.g., '1.5 MB', '1024 KB')."
13
+ spec.homepage = "https://github.com/stkossman/human_file_size"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
24
+
25
+ spec.metadata["homepage_uri"] = spec.homepage
26
+ spec.metadata["source_code_uri"] = "https://github.com/stkossman/human_file_size"
27
+ end
@@ -0,0 +1,3 @@
1
+ module HumanFileSize
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ module HumanFileSize
2
+ UNITS = %w[B KB MB GB TB PB EB ZB YB].freeze
3
+ BASE = 1024
4
+
5
+ def self.format(bytes, precision: 2)
6
+ return "0 B" if bytes.nil? || bytes.zero?
7
+
8
+ units = %w[B KB MB GB TB PB]
9
+ exponent = bytes.zero? ? 0 : (Math.log(bytes) / Math.log(1024)).to_i
10
+ exponent = [exponent, units.size - 1].min
11
+ value = bytes.to_f / (1024 ** exponent)
12
+
13
+ formatted_value = "%.#{precision}f" % value
14
+ "#{formatted_value} #{units[exponent]}"
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: human_file_size
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrii Stavskyi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-05-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Accepts a file size in bytes and returns a string with the appropriate
14
+ prefix (e.g., '1.5 MB', '1024 KB').
15
+ email:
16
+ - an.stawski@outlook.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".idea/.gitignore"
22
+ - ".idea/human_file_size.iml"
23
+ - ".idea/modules.xml"
24
+ - ".idea/vcs.xml"
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE
28
+ - README.md
29
+ - human_file_size.gemspec
30
+ - lib/human_file_size.rb
31
+ - lib/human_file_size/version.rb
32
+ homepage: https://github.com/stkossman/human_file_size
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ allowed_push_host: https://rubygems.org
37
+ homepage_uri: https://github.com/stkossman/human_file_size
38
+ source_code_uri: https://github.com/stkossman/human_file_size
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.5.22
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Formats file sizes into a human-readable format.
58
+ test_files: []