Class: Cups::Printer
- Inherits:
-
Object
- Object
- Cups::Printer
- Defined in:
- lib/cups/printer/printer.rb
Overview
Right now this just wraps the Cups.options_for hash using method_missing, allowing you to call things like Printer#printer_make_and_model on an instance.
Instance Method Summary collapse
-
#initialize(printer = nil) ⇒ Printer
constructor
Creates a Cups::Printer object.
-
#method_missing(m) ⇒ Object
Call an options key on this object (with hyphens substituted with underscores).
Constructor Details
#initialize(printer = nil) ⇒ Printer
Creates a Cups::Printer object. Defaults to the default printer, if there is one.
10 11 12 13 14 15 16 17 18 |
# File 'lib/cups/printer/printer.rb', line 10 def initialize(printer=nil) if printer.nil? raise "There is no default printer!" if !Cups.default_printer @printer = Cups.default_printer else raise "The printer or destination doesn't exist!" unless Cups.show_destinations.include?(printer) @printer = printer end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m) ⇒ Object
Call an options key on this object (with hyphens substituted with underscores). Passes onto super if no key is found or its value is nil.
22 23 24 25 26 |
# File 'lib/cups/printer/printer.rb', line 22 def method_missing(m) key = m.to_s.gsub(/\_/, "-") @options[key].nil? ? super : @options[key] end |