lib/windows/sys/filesystem.rb in sys-filesystem-1.1.1 vs lib/windows/sys/filesystem.rb in sys-filesystem-1.1.2

- old
+ new

@@ -17,11 +17,11 @@ # Error typically raised if any of the Sys::Filesystem methods fail. class Error < StandardError; end # The version of the sys-filesystem library. - VERSION = '1.1.1' + VERSION = '1.1.2' class Mount # The name of the volume. This is the device mapping. attr_reader :name @@ -53,11 +53,11 @@ class Stat # The path of the file system. attr_reader :path - # The file system block size. MS Windows typically defaults to 4096. + # The file system block size. MS Windows typically defaults to 4096. attr_reader :block_size # Fragment size. Meaningless at the moment. attr_reader :fragment_size @@ -75,11 +75,11 @@ # Total number of files/inodes that can be created on the file system. # This attribute is always nil on MS Windows. attr_reader :files # Total number of free files/inodes that can be created on the file - # system. This attribute is always nil on MS Windows. + # system. This attribute is always nil on MS Windows. attr_reader :files_free # Total number of available files/inodes for unprivileged processes # that can be created on the file system. This attribute is always # nil on MS Windows. @@ -95,13 +95,31 @@ attr_reader :name_max # The file system type, e.g. NTFS, FAT, etc. attr_reader :base_type + # Returns the total amount of free space on the partition. + attr_reader :bytes_free + alias inodes files alias inodes_free files_free alias inodes_available files_available + + # Returns the total space on the partition. + def bytes_total + blocks * block_size + end + + # Returns the total amount of used space on the partition. + def bytes_used + bytes_total - bytes_free + end + + # Returns the percentage of the partition that has been used. + def percent_used + 100 - (100.0 * bytes_free.to_f / bytes_total.to_f) + end end # Yields a Filesystem::Mount object for each volume on your system in # block form. Returns an array of Filesystem::Mount objects in non-block # form. @@ -311,10 +329,11 @@ stat_obj.instance_variable_set(:@blocks_free, blocks_free) stat_obj.instance_variable_set(:@name_max, name_max) stat_obj.instance_variable_set(:@base_type, base_type) stat_obj.instance_variable_set(:@flags, flags) stat_obj.instance_variable_set(:@filesystem_id, vol_serial) + stat_obj.instance_variable_set(:@bytes_free, bytes_free) stat_obj.freeze # Read-only object end private @@ -365,30 +384,38 @@ end end # Some convenient methods for converting bytes to kb, mb, and gb. # -class Fixnum +class Numeric # call-seq: - # <tt>fix</tt>.to_kb + # <tt>num</tt>.to_kb # - # Returns +fix+ in terms of kilobytes. + # Returns +num+ in terms of kilobytes. def to_kb self / 1024 end # call-seq: - # <tt>fix</tt>.to_mb + # <tt>num</tt>.to_mb # - # Returns +fix+ in terms of megabytes. + # Returns +num+ in terms of megabytes. def to_mb self / 1048576 end # call-seq: - # <tt>fix</tt>.to_gb + # <tt>num</tt>.to_gb # - # Returns +fix+ in terms of gigabytes. + # Returns +num+ in terms of gigabytes. def to_gb self / 1073741824 + end + + # call-seq: + # <tt>num</tt>.to_gb + # + # Returns +num+ in terms of terabytes. + def to_tb + self / 1099511627776 end end