Class: SAXMachine::SAXConfig::ElementConfig

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ ElementConfig

Returns a new instance of ElementConfig.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sax-machine/sax_element_config.rb', line 7

def initialize(name, options)
  @name = name.to_s
  
  if options.has_key?(:with)
    # for faster comparisons later
    @with = options[:with].to_a.flatten.collect {|o| o.to_s}
  else
    @with = nil
  end
  
  if options.has_key?(:value)
    @value = options[:value].to_s
  else
    @value = nil
  end
  
  @as = options[:as]
  @collection = options[:collection]
  
  if @collection
    @setter = "add_#{options[:as]}"
  else
    @setter = "#{@as}="
  end
  @data_class = options[:class]
  @required = options[:required]
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



5
6
7
# File 'lib/sax-machine/sax_element_config.rb', line 5

def collection
  @collection
end

#data_classObject (readonly)

Returns the value of attribute data_class.



5
6
7
# File 'lib/sax-machine/sax_element_config.rb', line 5

def data_class
  @data_class
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/sax-machine/sax_element_config.rb', line 5

def name
  @name
end

#setterObject (readonly)

Returns the value of attribute setter.



5
6
7
# File 'lib/sax-machine/sax_element_config.rb', line 5

def setter
  @setter
end

Instance Method Details

#attrs_match?(attrs) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/sax-machine/sax_element_config.rb', line 47

def attrs_match?(attrs)
  if @with
    @with == (@with & attrs)
  else
    true
  end
end

#collection?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/sax-machine/sax_element_config.rb', line 59

def collection?
  @collection
end

#columnObject



35
36
37
# File 'lib/sax-machine/sax_element_config.rb', line 35

def column
  @as || @name.to_sym
end

#has_value_and_attrs_match?(attrs) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/sax-machine/sax_element_config.rb', line 55

def has_value_and_attrs_match?(attrs)
  !@value.nil? && attrs_match?(attrs)
end

#required?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/sax-machine/sax_element_config.rb', line 39

def required?
  @required
end

#value_from_attrs(attrs) ⇒ Object



43
44
45
# File 'lib/sax-machine/sax_element_config.rb', line 43

def value_from_attrs(attrs)
  attrs.index(@value) ? attrs[attrs.index(@value) + 1] : nil
end