Class: SAXMachine::SAXConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/sax-machine/sax_config.rb,
lib/sax-machine/sax_element_config.rb,
lib/sax-machine/sax_collection_config.rb

Defined Under Namespace

Classes: CollectionConfig, ElementConfig

Instance Method Summary collapse

Constructor Details

#initializeSAXConfig

Returns a new instance of SAXConfig.



6
7
8
9
# File 'lib/sax-machine/sax_config.rb', line 6

def initialize
  @top_level_elements  = []
  @collection_elements = []
end

Instance Method Details

#add_collection_element(name, options) ⇒ Object



15
16
17
# File 'lib/sax-machine/sax_config.rb', line 15

def add_collection_element(name, options)
  @collection_elements << CollectionConfig.new(name, options)
end

#add_top_level_element(name, options) ⇒ Object



11
12
13
# File 'lib/sax-machine/sax_config.rb', line 11

def add_top_level_element(name, options)
  @top_level_elements << ElementConfig.new(name, options)
end

#collection_config(name) ⇒ Object



19
20
21
# File 'lib/sax-machine/sax_config.rb', line 19

def collection_config(name)
  @collection_elements.detect { |ce| ce.name.to_s == name.to_s }
end

#element_config_for_attribute(name, attrs) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/sax-machine/sax_config.rb', line 23

def element_config_for_attribute(name, attrs)
  element_configs = @top_level_elements.select do |element_config|
    element_config.name == name &&
    element_config.has_value_and_attrs_match?(attrs)
  end
  element_configs.empty? ? nil : element_configs
end

#element_config_for_tag(name, attrs) ⇒ Object



31
32
33
34
35
36
# File 'lib/sax-machine/sax_config.rb', line 31

def element_config_for_tag(name, attrs)
  @top_level_elements.detect do |element_config|
    element_config.name == name &&
    element_config.attrs_match?(attrs)
  end
end