# -*- coding: UTF-8 -*-
# Conversion Tool v0.1
# By Elektro H@cker
exit if Object.const_defined?(:Ocra)
def logo()
puts "
_______ _______ __
| _ || |.-----..-----.| |
|. 1___||.| | || _ || _ || |
|. |___ `-|. |-'|_____||_____||__|
|: 1 | |: |
|::.. . | |::.| Conversion
`-------' `---' Tool
"
end
def help()
print "
How to use it:
#{__FILE__.split('/').last.split('.').first}.exe {Size} {Unit} {To unit}
Units are: Bytes, KB, MB, GB, TB, PB.
Examples:
- Convert bytes to megabytes:
#{__FILE__.split('/').last.split('.').first}.exe 446.777.647.104 Bytes MB
- Convert megabytes to kilobytes:
#{__FILE__.split('/').last.split('.').first}.exe 44.33 MB KB
- Convert petabyte to all:
#{__FILE__.split('/').last.split('.').first}.exe 1 PB
"
Process.exit
end
def BytesToUnit (number)
@KILOBYTE = 1024.0
@MEGABYTE = 1024.0 * 1024.0
@GIGABYTE = 1024.0 * 1024.0 * 1024.0
@TERABYTE = 1024.0 * 1024.0 * 1024.0 * 1024.0
@PETABYTE = 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0
@Bytes = number.to_s + " Bytes"
@Kilos = (number / @KILOBYTE).to_s
if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
@Kilos = "KB too depth"
elsif not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
@Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
elsif
@Kilos = "0.0 KB".to_s
end # Kilos
@Megas = (number / @MEGABYTE).to_s
if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
@Megas = "MB too depth"
elsif not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
@Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
elsif
@Megas = "0.0 MB".to_s
end # Megas
@Gigas = (number / @GIGABYTE).to_s
if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
@Gigas = "GB too depth"
elsif not @Gigas.include? "-"
@Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
elsif
@Gigas = "0.0 GB".to_s
end # Gigas
@Teras = (number / @TERABYTE).to_s
if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
@Teras = "TB too depth"
elsif not @Teras.include? "-"
@Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
elsif
@Teras = "0.0 TB".to_s
end # Teras
@Petas = (number / @PETABYTE).to_s
if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
@Petas = "PB too depth"
elsif not @Petas.include? "-"
@Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
elsif
@Petas = "0.0 PB".to_s
end # Petas
end
def KBToUnit (number)
@BYTE = 1024.0
@MEGABYTE = 1024.0
@GIGABYTE = 1024.0 * 1024.0
@TERABYTE = 1024.0 * 1024.0 * 1024.0
@PETABYTE = 1024.0 * 1024.0 * 1024.0 * 1024.0
@Bytes = (number * @BYTE).to_s
if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
@Bytes = "Bytes too depth"
elsif @Bytes[0..2].eql? "0.0"
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
elsif
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
end # Bytes
@Kilos = number.to_s + " KB"
@Megas = (number / @MEGABYTE).to_s
if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
@Megas = "MB too depth"
elsif not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
@Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
elsif
@Megas = "0.0 MB".to_s
end # Megas
@Gigas = (number / @GIGABYTE).to_s
if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
@Gigas = "GB too depth"
elsif not @Gigas.include? "-"
@Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
elsif
@Gigas = "0.0 GB".to_s
end # Gigas
@Teras = (number / @TERABYTE).to_s
if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
@Teras = "TB too depth"
elsif not @Teras.include? "-"
@Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
elsif
@Teras = "0.0 TB".to_s
end # Teras
@Petas = (number / @PETABYTE).to_s
if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
@Petas = "PB too depth"
elsif not @Petas.include? "-"
@Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
elsif
@Petas = "0.0 PB".to_s
end # Petas
end
def MBToUnit (number)
@BYTE = 1024.0 * 1024.0
@KILOBYTE = 1024.0
@GIGABYTE = 1024.0
@TERABYTE = 1024.0 * 1024.0
@PETABYTE = 1024.0 * 1024.0 * 1024.0
@Bytes = (number * @BYTE).to_s
if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
@Bytes = "Bytes too depth"
elsif @Bytes[0..2].eql? "0.0"
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
elsif
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
end # Bytes
@Kilos = (number * @KILOBYTE).to_s
if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
@Kilos = "KB too depth"
elsif not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
@Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
elsif
@Kilos = "0.0 KB".to_s
end # Kilos
@Megas = number.to_s + " MB"
@Gigas = (number / @GIGABYTE).to_s
if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
@Gigas = "GB too depth"
elsif not @Gigas.include? "-"
@Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
elsif
@Gigas = "0.0 GB".to_s
end # Gigas
@Teras = (number / @TERABYTE).to_s
if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
@Teras = "TB too depth"
elsif not @Teras.include? "-"
@Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
elsif
@Teras = "0.0 TB".to_s
end # Teras
@Petas = (number / @PETABYTE).to_s
if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
@Petas = "PB too depth"
elsif not @Petas.include? "-"
@Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
elsif
@Petas = "0.0 PB".to_s
end # Petas
end
def GBToUnit (number)
@BYTE = 1024.0 * 1024.0 * 1024.0
@KILOBYTE = 1024.0 * 1024.0
@MEGABYTE = 1024.0
@TERABYTE = 1024.0
@PETABYTE = 1024.0 * 1024.0
@Bytes = (number * @BYTE).to_s
if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
@Bytes = "Bytes too depth"
elsif @Bytes[0..2].eql? "0.0"
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
elsif
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
end # Bytes
@Kilos = (number * @KILOBYTE).to_s
if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
@Kilos = "KB too depth"
elsif not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
@Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
elsif
@Kilos = "0.0 KB".to_s
end # Kilos
@Megas = (number * @MEGABYTE).to_s
if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
@Megas = "MB too depth"
elsif not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
@Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
elsif
@Megas = "0.0 MB".to_s
end # Megas
@Gigas = number.to_s + " GB"
@Teras = (number / @TERABYTE).to_s
if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
@Teras = "TB too depth"
elsif not @Teras.include? "-"
@Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
elsif
@Teras = "0.0 TB".to_s
end # Teras
@Petas = (number / @PETABYTE).to_s
if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
@Petas = "PB too depth"
elsif not @Petas.include? "-"
@Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
elsif
@Petas = "0.0 PB".to_s
end # Petas
end
def TBToUnit (number)
@BYTE = 1024.0 * 1024.0 * 1024.0 * 1024.0
@KILOBYTE = 1024.0 * 1024.0 * 1024.0
@MEGABYTE = 1024.0 * 1024.0
@GIGABYTE = 1024.0
@PETABYTE = 1024.0
@Bytes = (number * @BYTE).to_s
if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
@Bytes = "Bytes too depth"
elsif @Bytes[0..2].eql? "0.0"
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
elsif
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
end # Bytes
@Kilos = (number * @KILOBYTE).to_s
if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
@Kilos = "KB too depth"
elsif not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
@Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
elsif
@Kilos = "0.0 KB".to_s
end # Kilos
@Megas = (number * @MEGABYTE).to_s
if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
@Megas = "MB too depth"
elsif not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
@Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
elsif
@Megas = "0.0 MB".to_s
end # Megas
@Gigas = (number * @GIGABYTE).to_s
if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
@Gigas = "GB too depth"
elsif not @Gigas.include? "-"
@Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
elsif
@Gigas = "0.0 GB".to_s
end # Gigas
@Teras = number.to_s + " TB"
@Petas = (number / @PETABYTE).to_s
if number.to_s.length > 20 and @Petas.length > 3 and @Petas.split('.').first.length == 1
@Petas = "PB too depth"
elsif not @Petas.include? "-"
@Petas = @Petas.split('.').first + "." + @Petas.split('.').last[0..1] + " PB"
elsif
@Petas = "0.0 PB".to_s
end # Petas
end
def PBToUnit (number)
@BYTE = 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0
@KILOBYTE = 1024.0 * 1024.0 * 1024.0 * 1024.0
@MEGABYTE = 1024.0 * 1024.0 * 1024.0
@GIGABYTE = 1024.0 * 1024.0
@TERABYTE = 1024.0
@Bytes = (number * @BYTE).to_s
if number.to_s.length > 20 and @Bytes.length > 3 and @Bytes.split('.').first.length == 1
@Bytes = "Bytes too depth"
elsif @Bytes[0..2].eql? "0.0"
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0..1] + " Bytes"
elsif
@Bytes = @Bytes.split('.').first + "." + @Bytes.split('.').last[0] + " Bytes"
end # Bytes
@Kilos = (number * @KILOBYTE).to_s
if number.to_s.length > 20 and @Kilos.length > 3 and @Kilos.split('.').first.length == 1
@Kilos = "KB too depth"
elsif not @Kilos.include? "-" and not @Kilos[0..3].eql? "0.00"
@Kilos = @Kilos.split('.').first + "." + @Kilos.split('.').last[0..1] + " KB"
elsif
@Kilos = "0.0 KB".to_s
end # Kilos
@Megas = (number * @MEGABYTE).to_s
if number.to_s.length > 20 and @Megas.length > 3 and @Megas.split('.').first.length == 1
@Megas = "MB too depth"
elsif not @Megas.include? "-" and not @Megas[0..3].eql? "0.00"
@Megas = @Megas.split('.').first + "." + @Megas.split('.').last[0..1] + " MB"
elsif
@Megas = "0.0 MB".to_s
end # Megas
@Gigas = (number * @GIGABYTE).to_s
if number.to_s.length > 20 and @Gigas.length > 3 and @Gigas.split('.').first.length == 1
@Gigas = "GB too depth"
elsif not @Gigas.include? "-"
@Gigas = @Gigas.split('.').first + "." + @Gigas.split('.').last[0..1] + " GB"
elsif
@Gigas = "0.0 GB".to_s
end # Gigas
@Teras = (number * @TERABYTE).to_s
if number.to_s.length > 20 and @Teras.length > 3 and @Teras.split('.').first.length == 1
@Teras = "TB too depth"
elsif not @Teras.include? "-"
@Teras = @Teras.split('.').first + "." + @Teras.split('.').last[0..1] + " TB"
elsif
@Teras = "0.0 TB".to_s
end # Teras
@Petas = number.to_s + " PB"
end
# Error control
def args()
if ARGV.empty? or ARGV[0] == "/?" or ARGV[1] == nil or ARGV[2] == nil and not ARGV[1] == "bytes" and not ARGV[1] == "Bytes" and not ARGV[1] == "BYTES" and not ARGV[1] == "kb" and not ARGV[1] == "Kb" and not ARGV[1] == "KB" and not ARGV[1] == "kB" and not ARGV[1] == "mb" and not ARGV[1] == "Mb" and not ARGV[1] == "MB" and not ARGV[1] == "mB" and not ARGV[1] == "gb" and not ARGV[1] == "gB" and not ARGV[1] == "Gb" and not ARGV[1] == "GB" and not ARGV[1] == "tb" and not ARGV[1] == "Tb" and not ARGV[1] == "TB" and not ARGV[1] == "tB" and not ARGV[1] == "pb" and not ARGV[1] == "pB" and not ARGV[1] == "Pb" and not ARGV[1] == "PB"
help()
elsif not ARGV[2] == "bytes" and not ARGV[2] == "Bytes" and not ARGV[2] == "BYTES" and not ARGV[2] == "kb" and not ARGV[2] == "Kb" and not ARGV[2] == "KB" and not ARGV[2] == "kB" and not ARGV[2] == "mb" and not ARGV[2] == "Mb" and not ARGV[2] == "MB" and not ARGV[2] == "mB" and not ARGV[2] == "gb" and not ARGV[2] == "gB" and not ARGV[2] == "Gb" and not ARGV[2] == "GB" and not ARGV[2] == "tb" and not ARGV[2] == "Tb" and not ARGV[2] == "TB" and not ARGV[2] == "tB" and not ARGV[2] == "pb" and not ARGV[2] == "pB" and not ARGV[2] == "Pb" and not ARGV[2] == "PB"
$ToUnit = "all"
end
end
# Process
logo()
args()
input = ARGV[0]
unit = ARGV[1]
$ToUnit = ARGV[2]
input = input.gsub(',', '.')
if not input.length == 6 or not input.length == 5 and not input[-3] == "."
input = input.gsub('.', '')
input = input.to_i
elsif
input = input.to_f
end
if unit =~ /bytes/i
BytesToUnit(input)
elsif unit =~ /kb/i
KBToUnit(input)
elsif unit =~ /mb/i
MBToUnit(input)
elsif unit =~ /gb/i
GBToUnit(input)
elsif unit =~ /tb/i
TBToUnit(input)
elsif unit =~ /pb/i
PBToUnit(input)
end
if $ToUnit =~ /bytes/i
puts "#{input} #{unit} = #{@Bytes}"
elsif $ToUnit =~ /kb/i
puts "#{input} #{unit} = #{@Kilos}"
elsif $ToUnit =~ /mb/i
puts "#{input} #{unit} = #{@Megas}"
elsif $ToUnit =~ /gb/i
puts "#{input} #{unit} = #{@Gigas}"
elsif $ToUnit =~ /tb/i
puts "#{input} #{unit} = #{@Teras}"
elsif $ToUnit =~ /pb/i
puts "#{input} #{unit} = #{@Petas}"
elsif $ToUnit == nil
puts "#{input} #{unit} = #{@Bytes}"
puts "#{input} #{unit} = #{@Kilos}"
puts "#{input} #{unit} = #{@Megas}"
puts "#{input} #{unit} = #{@Gigas}"
puts "#{input} #{unit} = #{@Teras}"
puts "#{input} #{unit} = #{@Petas}"
end
__END__