class DopCommon::Utils::DataSize
Constants
- GIBIBYTE
- GIGABYTE
- KIBIBYTE
- KILOBYTE
- MEBIBYTE
- MEGABYTE
Public Class Methods
new(input)
click to toggle source
# File lib/dop_common/utils.rb, line 21 def initialize(input) @input ||= input end
Public Instance Methods
gibibytes()
click to toggle source
# File lib/dop_common/utils.rb, line 45 def gibibytes size / GIBIBYTE end
Also aliased as: g
gigabytes()
click to toggle source
# File lib/dop_common/utils.rb, line 60 def gigabytes size / GIGABYTE end
Also aliased as: gb
kibibytes()
click to toggle source
# File lib/dop_common/utils.rb, line 35 def kibibytes size / KIBIBYTE end
Also aliased as: k
kilobytes()
click to toggle source
# File lib/dop_common/utils.rb, line 50 def kilobytes size / KILOBYTE end
Also aliased as: kb
mebibytes()
click to toggle source
# File lib/dop_common/utils.rb, line 40 def mebibytes size / MEBIBYTE end
Also aliased as: m
megabytes()
click to toggle source
# File lib/dop_common/utils.rb, line 55 def megabytes size / MEGABYTE end
Also aliased as: mb
size()
click to toggle source
# File lib/dop_common/utils.rb, line 29 def size @size ||= input_valid? ? create_size : nil end
to_s()
click to toggle source
# File lib/dop_common/utils.rb, line 65 def to_s size.to_s end
validate()
click to toggle source
# File lib/dop_common/utils.rb, line 25 def validate log_validation_method(:input_valid?) end
Private Instance Methods
create_size()
click to toggle source
# File lib/dop_common/utils.rb, line 82 def create_size if @input.kind_of?(String) if @input.index(/K$/) s = @input.sub(/K$/, '').to_f * KIBIBYTE elsif @input.index(/M$/) s = @input.sub(/M$/, '').to_f * MEBIBYTE elsif @input.index(/G$/) s = @input.sub(/G$/, '').to_f * GIBIBYTE elsif @input.index(/KB$/) s = @input.sub(/KB$/, '').to_f * KILOBYTE elsif @input.index(/MB$/) s = @input.sub(/MB$/, '').to_f * MEGABYTE elsif @input.index(/GB$/) s = @input.sub(/GB$/, '').to_f * GIGABYTE else s = @input end @size = s.to_i else @size = @input end end
input_valid?()
click to toggle source
# File lib/dop_common/utils.rb, line 71 def input_valid? raise PlanParsingError, "DataSize: Invalid input '#{@input}'. It must be an integer or string" unless [String, Fixnum].include?(@input.class) raise PlanParsingError, "DataSize: Invalid input '#{@input}'. It must be greater than zero" if @input.kind_of?(Fixnum) && @input < 1 raise PlanParsingError, "DataSize: Invalid input '#{@input}'. " \ "It must be a positive number followed by one of K,KB,M,MB,G,GB literals" if @input.kind_of?(String) && @input !~ /^(([1-9]\d*)(\.\d+)?|0\.(0*[1-9]\d*))[KMG]B?$/ true end