Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/bytesize.rb

Overview

ByteSize adds three new methods to the File class:

  • ::bytesize

  • ::bytesize?

  • #bytesize

Plus the equivalent methods for IECByteSize:

  • ::iecbytesize

  • ::iecbytesize?

  • #iecbytesize

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.bytesize(file_name) ⇒ Object

:call-seq:

File.bytesize( file_name )  ->  bytesize

Identical to size[http://ruby-doc.org/core/File.html#method-c-size] except that the value is returned as an instance of ByteSize.



1132
1133
1134
# File 'lib/bytesize.rb', line 1132

def self.bytesize( file_name )
	ByteSize.new( self.size(file_name) )
end

.bytesize?(file_name) ⇒ Boolean

:call-seq:

File.bytesize?( file_name )  ->  bytesize or nil

Identical to size?[http://ruby-doc.org/core/File.html#method-c-size-3F] except that the value is returned as an instance of ByteSize.

Returns:

  • (Boolean)


1145
1146
1147
1148
# File 'lib/bytesize.rb', line 1145

def self.bytesize?( file_name )
	sz = self.size?(file_name)
	sz.nil? ? nil : ByteSize.new(sz)
end

.iecbytesize(file_name) ⇒ Object

:call-seq:

File.iecbytesize( file_name )  ->  bytesize

Identical to size[http://ruby-doc.org/core/File.html#method-c-size] except that the value is returned as an instance of IECByteSize.



1172
1173
1174
# File 'lib/bytesize.rb', line 1172

def self.iecbytesize( file_name )
	IECByteSize.new( self.size(file_name) )
end

.iecbytesize?(file_name) ⇒ Boolean

:call-seq:

File.iecbytesize?( file_name )  ->  bytesize or nil

Identical to size?[http://ruby-doc.org/core/File.html#method-c-size-3F] except that the value is returned as an instance of IECByteSize.

Returns:

  • (Boolean)


1185
1186
1187
1188
# File 'lib/bytesize.rb', line 1185

def self.iecbytesize?( file_name )
	sz = self.size?(file_name)
	sz.nil? ? nil : IECByteSize.new(sz)
end

Instance Method Details

#bytesizeObject

:call-seq:

bytesize  ->  bytesize

Identical to #size[http://ruby-doc.org/core/File.html#method-i-size] except that the value is returned as an instance of ByteSize.



1159
1160
1161
# File 'lib/bytesize.rb', line 1159

def bytesize
	ByteSize.new(size)
end

#iecbytesizeObject

:call-seq:

iecbytesize  ->  bytesize

Identical to #size[http://ruby-doc.org/core/File.html#method-i-size] except that the value is returned as an instance of IECByteSize.



1199
1200
1201
# File 'lib/bytesize.rb', line 1199

def iecbytesize
	IECByteSize.new(size)
end