Open drusepth opened 7 years ago
I don't see any reason not to support negative sizes. Via Filesize.new
, one can already provide negative sizes; however they won't pretty print correctly, as the formula used assumes positive sizes.
I'd accept a PR that adds parsing of negative sizes, and correctly handles them in pretty printing.
Unrelated: You probably shouldn't be using #from
to create these file size objects. You already have a numeric value, current_user.bandwidth_kb
and a known unit, KB
. It'd make much more sense to use Filesize.new(current_user.bandwidth_kb * 1000)
here and avoid the whole parsing machinery.
Is there a reason this gem doesn't parse negative filesizes (e.g.
-50KB
)? Seems like when you're talking about memory capacities, it'd often make sense to talk about the absence of space (one example use-case given below). I'd be happy to include a PR if it was accidentally left out.My use-case:
I would assume negative filesizes are a lot harder to convert from one format to another; is that true? I'd of course love to be able to parse negative filesizes and pretty-print them. :+1:
Reproduction steps: