Class: Browserconfig

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

Overview

Build browserconfig XML

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#documentObject

Returns the value of attribute document.



5
6
7
# File 'lib/browserconfig.rb', line 5

def document
  @document
end

Instance Method Details

#add(path, element, attributes = {}, text = nil) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/browserconfig.rb', line 17

def add(path, element, attributes = {}, text = nil)
  parent = @document.elements[path]
  parent.elements[element] = REXML::Element.new element
  attributes.each do |key, value|
    parent.elements[element].add_attribute key, value
  end
  parent.add_text text if text
end

#dumpObject



26
27
28
29
30
31
32
# File 'lib/browserconfig.rb', line 26

def dump
  output = ''
  formatter = REXML::Formatters::Pretty.new 2
  formatter.compact = true
  formatter.write @document, output
  output
end

#load(source_path, config, prefix) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/browserconfig.rb', line 7

def load(source_path, config, prefix)
  @document = if File.exist? source_path
                REXML::Document.new File.read source_path
              else
                REXML::Document.new
              end
  add_browserconfig_schema
  add_browserconfig_elements config, prefix
end