Permalink
Browse files

Working copy: CPU, Display, GraphicsAdapter, GPU, OS

  • Loading branch information...
1 parent afbeff0 commit d0a7dd405b3ee598e3e259722b704918b9973e5b Ryan Scott Lewis committed Feb 11, 2016
Showing with 423 additions and 205 deletions.
  1. +5 −10 lib/system/cpu.rb
  2. +154 −0 lib/system/display.rb
  3. +9 −0 lib/system/gpu.rb
  4. +159 −0 lib/system/graphics_adapter.rb
  5. +96 −99 lib/system/os.rb
  6. +0 −96 lib/system/screen.rb
View
15 lib/system/cpu.rb 100644 → 100755
@@ -1,26 +1,21 @@
-require 'system'
-
-class System
-
- # Information about the current CPU(s) running on the current system.
- #
+module System
+ # Information about the current central processing units (CPUs) running on the current system.
+ #
# @since 0.1.1
class CPU
class << self
-
# The CPU count of the system, including individual CPU cores.
#
# @return [Integer] Count of CPU cores.
# @since 0.1.1
def count
return Java::Java.lang.Runtime.getRuntime.availableProcessors if System::Ruby.java?
- return File.read('/proc/cpuinfo').scan(/^processor\s*:/).size if File.exist?('/proc/cpuinfo')
- require 'win32ole'
+ return File.read("/proc/cpuinfo").scan(/^processor\s*:/).size if File.exist?("/proc/cpuinfo")
+ require "win32ole"
WIN32OLE.connect("winmgmts://").ExecQuery("select * from Win32_ComputerSystem").NumberOfProcessors
rescue LoadError
Integer `sysctl -n hw.ncpu 2>/dev/null` rescue 1
end
-
end
end
end
View
@@ -0,0 +1,154 @@
+require "system/helpers/has_attributes"
+require "system/os"
+require "system/dimensions"
+
+module System
+ # Information about the computer's attached display(s).
+ #
+ # @since 0.2.0
+ class Display
+ class << self
+ # Get all displays attached to the current host.
+ #
+ # @return [<Display>]
+ # @since 0.2.0
+ def all
+ # TODO
+ end
+
+ # The current host's primary Display.
+ #
+ # @return [Display]
+ # @since 0.2.0
+ def primary
+ instance = new
+
+ if OS.windows? # NOTE: http://stackoverflow.com/a/4631379/139089
+ require "dl/import"
+ require "dl/struct"
+
+ user32 = DL.dlopen("user32")
+ get_system_metrics = user32["GetSystemMetrics", "ILI"]
+
+ instance.width = get_system_metrics.call(0, 0)
+ instance.height = get_system_metrics.call(1, 0)
+ elsif OS.darwin? # TODO: Move into DisplayAdapter This whole method should just be `DisplayAdapter.first.displays.first`
+ # require "yaml"
+ #
+ # display_data = YAML.load(`system_profiler SPDisplaysDataType`)["Graphics/Displays"]
+ # displays = display_data.each_with_object([]) do |graphics_cards, memo|
+ # graphics_cards.each do |graphics_card|
+ # # TODO:
+ # # System::GraphicsAdapter
+ # # AKA video adapter, display card, graphics card, graphics board, display adapter, graphics adapter (dunno what to name it)
+ # # System::GPU
+ # graphics_card["Displays"].collect do |display|
+ # display[1]["Resolution"]
+ # end
+ # end
+ # end.flatten
+
+ width, height = resolutions.first.scan(/(\d+) x (\d+)/).flatten
+ # TODO: Validate!
+ # TODO: All this other stuff, including the refresh rate
+ # Resolution: 1920 x 1080 @ 60Hz (1080p)
+ # Pixel Depth: 32-Bit Color (ARGB8888)
+ # Display Serial Number: LTS0R0262400
+ # Main Display: Yes
+ # Mirror: On
+ # Mirror Status: Master Mirror
+ # Online: Yes
+ # Rotation: Supported
+ # Television: Yes
+ instance.width = width
+ instance.height = height
+ elsif OS.unix?
+ width, height = `xrandr`.scan(/current (\d+) x (\d+)/).flatten
+ # TODO: Validate!
+ instance.width = width
+ instance.height = height
+ end
+
+ instance
+ end
+
+ # Get the resolution of the primary display.
+ #
+ # @return [Dimensions]
+ # @since 0.2.0
+ def resolution
+ primary.resolution
+ end
+
+ # Get the width of the primary display.
+ #
+ # @return [Integer]
+ # @since 0.2.0
+ def width
+ resolution.width
+ end
+
+ # Get the height of the primary display.
+ #
+ # @return [Integer]
+ # @since 0.2.0
+ def height
+ resolution.height
+ end
+ end
+
+ include Helpers::HasAttributes
+
+ def initialize(attributes={})
+ @resolution = Dimensions.new
+
+ update_attributes(attributes)
+ end
+
+ # @method resolution
+ # Get the resolution.
+ #
+ # @return [Dimensions]
+
+ # @method resolution=
+ # Set the resolution.
+ #
+ # @param [Dimensions]
+ # @return [Dimensions]
+ attribute(:resolution) do |value|
+ return nil if value.nil?
+
+ value.is_a?(Dimensions) ? value : Dimensions.new(value)
+ end
+
+ # Get the width.
+ #
+ # @return [Integer]
+ def width
+ @resolution.width
+ end
+
+ # Set the width.
+ #
+ # @param [#to_i] value
+ # @return [Integer]
+ def width=(value)
+ @resolution.width = value
+ end
+
+ # Get the height.
+ #
+ # @return [Integer]
+ def height
+ @resolution.height
+ end
+
+ # Set the height.
+ #
+ # @param [#to_i] value
+ # @return [Integer]
+ def height=(value)
+ @resolution.height = value
+ end
+ end
+end
View
@@ -0,0 +1,9 @@
+module System
+ # Information about the graphics processing units (GPUs) installed on the currently running system.
+ #
+ # @since 0.2.0
+ class GPU
+ class << self
+ end
+ end
+end
@@ -0,0 +1,159 @@
+require "system/display"
+
+module System
+ # Information about the graphics adapters installed on the currently running system.
+ #
+ # @since 0.2.0
+ class GraphicsAdapter
+ class << self
+ end
+
+ # @method chipset_model
+ # Get the chipset model.
+ #
+ # @return [nil, String]
+ # @since 0.2.0
+
+ # @method chipset_model=
+ # Set the chipset model.
+ #
+ # @param [nil, #to_s] value
+ # @return [nil, String]
+ # @since 0.2.0
+ attribute(:chipset_model) { |value| validate_optional_string(value) }
+
+ # @method vram
+ # Get the amount of VRAM.
+ #
+ # @return [nil, Integer]
+ # @since 0.2.0
+
+ # @method vram=
+ # Set the amount of VRAM.
+ #
+ # @param [nil, #to_i] value
+ # @return [nil, Integer]
+ # @since 0.2.0
+ attribute(:vram) { |value| validate_optional_integer(value) }
+
+ # @method wram
+ # Get the amount of WRAM.
+ #
+ # @return [nil, Integer]
+ # @since 0.2.0
+
+ # @method wram=
+ # Set the amount of WRAM.
+ #
+ # @param [nil, #to_i] value
+ # @return [nil, Integer]
+ # @since 0.2.0
+ attribute(:wram) { |value| validate_optional_integer(value) }
+
+ # @method mdram
+ # Get the amount of MDRAM.
+ #
+ # @return [nil, Integer]
+ # @since 0.2.0
+
+ # @method mdram=
+ # Set the amount of MDRAM.
+ #
+ # @param [nil, #to_i] value
+ # @return [nil, Integer]
+ # @since 0.2.0
+ attribute(:mdram) { |value| validate_optional_integer(value) }
+
+ # @method sgram
+ # Get the amount of SGRAM.
+ #
+ # @return [nil, Integer]
+ # @since 0.2.0
+
+ # @method sgram=
+ # Set the amount of SGRAM.
+ #
+ # @param [nil, #to_i] value
+ # @return [nil, Integer]
+ # @since 0.2.0
+ attribute(:sgram) { |value| validate_optional_integer(value) }
+
+ # @method vendor_name
+ # Get the vendor name.
+ #
+ # @return [nil, String]
+ # @since 0.2.0
+
+ # @method vendor_name=
+ # Set the vendor name.
+ #
+ # @param [nil, #to_s] value
+ # @return [nil, String]
+ # @since 0.2.0
+ attribute(:vendor_name) { |value| validate_optional_string(value) }
+
+ # @method vendor_id
+ # Get the vendor id.
+ #
+ # @return [nil, String]
+ # @since 0.2.0
+
+ # @method vendor_id=
+ # Set the vendor id.
+ #
+ # @param [nil, #to_s] value
+ # @return [nil, String]
+ # @since 0.2.0
+ attribute(:vendor_id) { |value| validate_optional_integer(value) }
+
+ # @method device_id
+ # Get the device id.
+ #
+ # @return [nil, String]
+ # @since 0.2.0
+
+ # @method device_id=
+ # Set the device id.
+ #
+ # @param [nil, #to_s] value
+ # @return [nil, String]
+ # @since 0.2.0
+ attribute(:device_id) { |value| validate_optional_integer(value) }
+
+ # @method revision_id
+ # Get the revision id.
+ #
+ # @return [nil, String]
+ # @since 0.2.0
+
+ # @method revision_id=
+ # Set the revision id.
+ #
+ # @param [nil, #to_s] value
+ # @return [nil, String]
+ # @since 0.2.0
+ attribute(:revision_id) { |value| validate_optional_integer(value) }
+
+ # Get the displays attached to this display adapter.
+ #
+ # @return [<DisplayAdapter>]
+ # @since 0.2.0
+ def displays
+ # TODO
+ end
+
+ protected
+
+ def validate_optional_integer(value)
+ return nil if value.nil?
+
+ value.to_i
+ end
+
+ def validate_optional_string(value)
+ return nil if value.nil?
+
+ value.to_s.strip
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit d0a7dd4

Please sign in to comment.