megabytes 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88eca9e82cce80ea1980590621bca8230de5facc
4
+ data.tar.gz: a6db8b011689660027c4293077e5fe4256767695
5
+ SHA512:
6
+ metadata.gz: e80c6bcde8ba7cea04683b50c0716949f4e0d0ae3716b06f192a0b80f12334752f61d75fb97faefea1f7ed03426b448676939060468f4acca20706fce120e6aa
7
+ data.tar.gz: fa6361cc55b9345b892896bb159dd68d0f8225681f160c66d790e17322cc1274415155801de9e7e46f2ee0428b3fd3ac8f0481712045e3b8d715dc23df166e54
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", "~> 3.2.0"
5
+ gem "yard"
6
+ gem "bundler", "~> 1.0"
7
+ gem "jeweler", "~> 2.0.1"
8
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 WeTransfer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # megabytes
2
+
3
+ Format your byte sizes as megabytes/kilobytes. For when ActiveSupport is too much. Use as a module that
4
+ you include, or as a standalone module. The module is compatible with Opal as well.
5
+
6
+ Megabytes.megabytes(898218921)) #=> "856.61MB"
7
+
8
+ ## Contributing to megabytes
9
+
10
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
11
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
12
+ * Fork the project.
13
+ * Start a feature/bugfix branch.
14
+ * Commit and push until you are happy with your contribution.
15
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
16
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
17
+
18
+ ## Copyright
19
+
20
+ Copyright (c) 2015 WeTransfer. See LICENSE.txt for
21
+ further details.
22
+
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+ require_relative 'lib/megabytes'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
18
+ gem.version = Megabytes::VERSION
19
+ gem.name = "megabytes"
20
+ gem.homepage = "https://github.com/wetransfer/megabytes"
21
+ gem.license = "MIT"
22
+ gem.description = %Q{Byte size formatter for when ActiveSupport is too much}
23
+ gem.summary = %Q{Format byte sizes with this tiny library}
24
+ gem.email = "me@julik.nl"
25
+ gem.authors = ["Julik Tarkhanov"]
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ task :default => :spec
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "megabytes #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
@@ -0,0 +1,23 @@
1
+ # A tiny byte size formatter for when you don't need or do not want to use ActiveSupport.
2
+ module Megabytes
3
+ VERSION = '1.0.0'
4
+ PAIRS = {
5
+ 'B' => 1024,
6
+ 'KB' => 1024 ** 2,
7
+ 'MB' => 1024 ** 3,
8
+ 'GB' => 1024 ** 4,
9
+ 'TB' => 1024 ** 5,
10
+ 'PB' => 1024 ** 6,
11
+ }.freeze
12
+
13
+ # Returns a formatted byte count for easy reading. Bytes are counted using
14
+ # the 1024 quantifier.
15
+ #
16
+ # @param bytes[Fixnum,Bignum] the number of bytes to display
17
+ # @return [String] the formatted size in kilo/mega/giga/tera/whatever bytes
18
+ def megabytes(bytes)
19
+ PAIRS.each_pair { |e, s| return [(bytes.to_f / (s / 1024)).round(2), e].join if bytes < s }
20
+ end
21
+
22
+ extend self
23
+ end
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: megabytes 1.0.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "megabytes"
9
+ s.version = "1.0.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
13
+ s.authors = ["Julik Tarkhanov"]
14
+ s.date = "2015-12-27"
15
+ s.description = "Byte size formatter for when ActiveSupport is too much"
16
+ s.email = "me@julik.nl"
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rspec",
24
+ "Gemfile",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "lib/megabytes.rb",
29
+ "megabytes.gemspec",
30
+ "spec/megabytes_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = "https://github.com/wetransfer/megabytes"
34
+ s.licenses = ["MIT"]
35
+ s.rubygems_version = "2.2.2"
36
+ s.summary = "Format byte sizes with this tiny library"
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 4
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_development_dependency(%q<rspec>, ["~> 3.2.0"])
43
+ s.add_development_dependency(%q<yard>, [">= 0"])
44
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
46
+ else
47
+ s.add_dependency(%q<rspec>, ["~> 3.2.0"])
48
+ s.add_dependency(%q<yard>, [">= 0"])
49
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<rspec>, ["~> 3.2.0"])
54
+ s.add_dependency(%q<yard>, [">= 0"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
56
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
57
+ end
58
+ end
59
+
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Megabytes" do
4
+ it "formats filesizes" do
5
+ h = Megabytes
6
+ expect(h.megabytes(123)).to eq("123.0B")
7
+ expect(h.megabytes(8096)).to eq("7.91KB")
8
+ expect(h.megabytes(898218921)).to eq("856.61MB")
9
+ expect(h.megabytes(4588758874555558)).to eq("4.08PB")
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rspec'
5
+ require 'megabytes'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ config.order = 'random'
13
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: megabytes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Julik Tarkhanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ description: Byte size formatter for when ActiveSupport is too much
70
+ email: me@julik.nl
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files:
74
+ - LICENSE.txt
75
+ - README.md
76
+ files:
77
+ - ".document"
78
+ - ".rspec"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/megabytes.rb
84
+ - megabytes.gemspec
85
+ - spec/megabytes_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: https://github.com/wetransfer/megabytes
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Format byte sizes with this tiny library
111
+ test_files: []