Skip to content

Commit

Permalink
mark format rate private as it is unused
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Feb 4, 2015
1 parent 9b3e272 commit 0636454
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 31 deletions.
39 changes: 19 additions & 20 deletions library/types/src/modules/String.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,6 @@ def FormatSize(bytes)
FormatSizeWithPrecision(bytes, -1, Ops.less_than(bytes, 1 << 20))
end

# Return a pretty description of a download rate
#
# Return a pretty description of a download rate, with two fraction digits
# and using B/s, KiB/s, MiB/s, GiB/s or TiB/s as unit as appropriate.
#
# @param [Fixnum] bytes_per_second download rate (in B/s)
# @return formatted string
#
# @example FormatRate(6780) -> ""
# @example FormatRate(0) -> ""
# @example FormatRate(895321) -> ""
def FormatRate(bytes_per_second)
# covert a number to download rate string
# %1 is string - size in bytes, B, KiB, MiB, GiB or TiB
Builtins.sformat(_("%1/s"), FormatSize(bytes_per_second))
end

# Add a download rate status to a message.
#
# Add the current and the average download rate to the message.
Expand All @@ -241,7 +224,7 @@ def FormatRateMessage(text, avg_bps, curr_bps)
rate = ""

if Ops.greater_than(curr_bps, 0)
rate = FormatRate(curr_bps)
rate = format_rate(curr_bps)

if Ops.greater_than(avg_bps, 0)
# format download rate message: %1 = the current download rate (e.g. "242.6kB/s")
Expand All @@ -250,7 +233,7 @@ def FormatRateMessage(text, avg_bps, curr_bps)
rate = Builtins.sformat(
_("%1 (on average %2)"),
rate,
FormatRate(avg_bps)
format_rate(avg_bps)
)
end
end
Expand Down Expand Up @@ -1140,7 +1123,6 @@ def ReplaceWith(str, chars, glue)
publish function: :YesNo, type: "string (boolean)"
publish function: :FormatSizeWithPrecision, type: "string (integer, integer, boolean)"
publish function: :FormatSize, type: "string (integer)"
publish function: :FormatRate, type: "string (integer)"
publish function: :FormatRateMessage, type: "string (string, integer, integer)"
publish function: :FormatTime, type: "string (integer)"
publish function: :CutBlanks, type: "string (string)"
Expand Down Expand Up @@ -1178,6 +1160,23 @@ def ReplaceWith(str, chars, glue)
def opt_format(f, s)
s == "" || s.nil? ? "" : Builtins.sformat(f, s)
end

# Return a pretty description of a download rate
#
# Return a pretty description of a download rate, with two fraction digits
# and using B/s, KiB/s, MiB/s, GiB/s or TiB/s as unit as appropriate.
#
# @param [Fixnum] bytes_per_second download rate (in B/s)
# @return formatted string
#
# @example format_rate(6780) -> ""
# @example format_rate(0) -> ""
# @example format_rate(895321) -> ""
def format_rate(bytes_per_second)
# covert a number to download rate string
# %1 is string - size in bytes, B, KiB, MiB, GiB or TiB
Builtins.sformat(_("%1/s"), FormatSize(bytes_per_second))
end
end

String = StringClass.new
Expand Down
11 changes: 0 additions & 11 deletions library/types/test/string_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,17 +412,6 @@
end
end

describe ".FormatRate" do
it "returns pretty description of number passed as download rate" do

This comment has been minimized.

Copy link
@ancorgs

ancorgs Feb 10, 2015

Contributor

Shouldn't we move this test to ".FormatRateMessage" instead of removing it?

This comment has been minimized.

Copy link
@jreidinger

jreidinger Feb 10, 2015

Author Member

actually it is tested in it "returns text with %1 replaced by formated rate for average and current download" . The second test case cannot happen as FormatRateMessage never pass nil.

This comment has been minimized.

Copy link
@ancorgs

ancorgs Feb 10, 2015

Contributor

Yeah, I was only talking about the first one. I already noticed the second one is not a problem. But I though that the formating of the first test (that "1.001 GiB/s") was worth keeping. The examples on the other tests ("1 KiB/s" and "1.00 MiB/s") are more straightforward.

This comment has been minimized.

Copy link
@jreidinger

jreidinger Feb 10, 2015

Author Member

OK, I add it.

expect(subject.FormatRate(1025 << 20)).to eq "1.001 GiB/s"
end

# FIXME: looks like bug
it "returns \"/s\" if nil is passed" do
expect(subject.FormatRate(nil)).to eq "/s"
end
end

describe ".FormatRateMessage" do
it "returns text with %1 replaced by formated rate for average and current download " do
expect(subject.FormatRateMessage("Downloading %1", 1 << 20, 1 << 10)).to eq "Downloading 1 KiB/s (on average 1.00 MiB/s)"
Expand Down

0 comments on commit 0636454

Please sign in to comment.