infobar 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30321a676adb1405f01c5273b4df778fa09e9756178126e40226c202f5f94c8c
4
- data.tar.gz: a7ca0c2ec7a10037ff986bd50c1aa2ab6cafba2ef1921150bb40a4a967763dac
3
+ metadata.gz: 6be0ff22b6b4cff7706761d7362eef626b328500026c47a13594069a4891f9e1
4
+ data.tar.gz: 0ffe940091eb19ede807132116d24a65492380f4d0f23b23c7e686643369818f
5
5
  SHA512:
6
- metadata.gz: 1af9240372902d1a881ee216b3ac5a3691c11dbb0c7647bc76770252c87ec616d0e63c96ef97415da3d82acb57e11441f10d2786c4347a9be93a5e9fc427a714
7
- data.tar.gz: c2a49d419ef3a482612a10a8034fefcd8da583b6bdec35b17949aa838bda81df2ee1d7874c78636864dda6a9275635c45b72df4b05afd8593f929b87b48508ce
6
+ metadata.gz: 493f9b92d05a2bb2ad01abae64d042865fc6ee69e1c949548b8f6c50fd6f8f81adc5f2f54fc9d3cf1aecea9f95bc0b66593e3d89e7f3ee3a591cf164018f22d1
7
+ data.tar.gz: 737d899878bacb22bd7cf417cd6eab20561c2f902021f7646947bfe3280cb908135953de5b05124ed10506a579f08ee548428c11687d0c2efa9c2d23b4ba0e9c
@@ -1,6 +1,7 @@
1
1
  rvm:
2
- - 2.3.3
3
- - 2.4.2
2
+ - 2.3
3
+ - 2.4
4
+ - 2.5
4
5
  - ruby-head
5
6
  - jruby-head
6
7
  sudo: false
data/README.md CHANGED
@@ -21,6 +21,9 @@ Display progress of computations and additional information to the terminal.
21
21
 
22
22
  ## Changes
23
23
 
24
+ * 2018-03-05 Release 0.5.0
25
+ - Allow counter values to be formatted with units.
26
+
24
27
  * 2017-12-08 Release 0.4.0
25
28
  - Automatically iterate when `with_infobar` is passed a block.
26
29
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: infobar 0.4.0 ruby lib
2
+ # stub: infobar 0.5.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "infobar".freeze
6
- s.version = "0.4.0"
6
+ s.version = "0.5.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2017-12-08"
11
+ s.date = "2018-03-05"
12
12
  s.description = "This gem displays progress of computations and additional information to the terminal.".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.extra_rdoc_files = ["README.md".freeze, "lib/infobar.rb".freeze, "lib/infobar/counter.rb".freeze, "lib/infobar/display.rb".freeze, "lib/infobar/duration.rb".freeze, "lib/infobar/fancy_interface.rb".freeze, "lib/infobar/fifo.rb".freeze, "lib/infobar/frequency.rb".freeze, "lib/infobar/input_output.rb".freeze, "lib/infobar/message.rb".freeze, "lib/infobar/number.rb".freeze, "lib/infobar/rate.rb".freeze, "lib/infobar/spinner.rb".freeze, "lib/infobar/timer.rb".freeze, "lib/infobar/trend.rb".freeze, "lib/infobar/version.rb".freeze]
@@ -1,9 +1,17 @@
1
1
  class Infobar::Number
2
- def initialize(value, format: nil, separate: nil)
2
+ def initialize(value, format: nil, unit: nil, prefix: 1000, separate: nil)
3
3
  duration = Tins::Duration.new(value)
4
- @string = format ? format % value : value.to_s
5
- if Integer === value && separate
6
- @string.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{separate}")
4
+ case format
5
+ when /%U/
6
+ unit ||= 'i/s'
7
+ prefix ||= 1000
8
+ @string = Tins::Unit.format(value, format: format, unit: unit, prefix: prefix)
9
+ else
10
+ format ||= '%f'
11
+ @string = format ? format % value : value.to_s
12
+ if Integer === value && separate
13
+ @string.gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{separate}")
14
+ end
7
15
  end
8
16
  end
9
17
 
@@ -1,6 +1,6 @@
1
1
  class Infobar
2
2
  # Infobar version
3
- VERSION = '0.4.0'
3
+ VERSION = '0.5.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -8,5 +8,16 @@ describe Infobar::Number do
8
8
  it 'can convert number into string for format' do
9
9
  expect(described_class.new(Math::PI, format: '%.3f').to_s).to eq '3.142'
10
10
  end
11
+
12
+ it 'can convert number into string for unit format' do
13
+ expect(
14
+ described_class.new(
15
+ 1e6 * Math::PI,
16
+ unit: ?B,
17
+ prefix: 1024,
18
+ format: '%.3f%U'
19
+ ).to_s
20
+ ).to eq '2.996MB'
21
+ end
11
22
  end
12
23
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infobar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-08 00:00:00.000000000 Z
11
+ date: 2018-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar