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.



1140
1141
1142
# File 'lib/bytesize.rb', line 1140

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)


1153
1154
1155
1156
# File 'lib/bytesize.rb', line 1153

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.



1180
1181
1182
# File 'lib/bytesize.rb', line 1180

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)


1193
1194
1195
1196
# File 'lib/bytesize.rb', line 1193

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.



1167
1168
1169
# File 'lib/bytesize.rb', line 1167

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.



1207
1208
1209
# File 'lib/bytesize.rb', line 1207

def iecbytesize
	IECByteSize.new(size)
end