Class: Foomatic::DB

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ DB

Returns a new instance of DB.



13
14
15
# File 'lib/foomatic.rb', line 13

def initialize(path)
  @path = Pathname.new(path)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



11
12
13
# File 'lib/foomatic.rb', line 11

def path
  @path
end

Class Method Details

.open(path = "/usr/share/foomatic/db") ⇒ Object



7
8
9
# File 'lib/foomatic.rb', line 7

def self.open(path = "/usr/share/foomatic/db")
  new(path)
end

Instance Method Details

#printersObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/foomatic.rb', line 17

def printers
  path.join("source", "printer").each_child.map do |f|
    xml = Nokogiri::XML.parse(f)
    Printer.new.tap do |printer|
      printer.id    = xml.root.attribute("id").to_s
      printer.make  = xml.root.xpath("make").text
      printer.model = xml.root.xpath("model").text
      printer.url   = xml.root.xpath("url").text
      Printer::MECHANISM_TYPES.each do |type|
        printer.send("#{type}=", xml.root.xpath("mechanism/#{type}").any?)
      end
    end
  end
end