Class: SAXMachine::SAXConfig::ElementConfig
- Inherits:
-
Object
- Object
- SAXMachine::SAXConfig::ElementConfig
- Defined in:
- lib/sax-machine/sax_element_config.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#setter ⇒ Object
readonly
Returns the value of attribute setter.
Instance Method Summary collapse
- #attrs_match?(attrs) ⇒ Boolean
- #collection? ⇒ Boolean
- #has_value_and_attrs_match?(attrs) ⇒ Boolean
-
#initialize(name, options) ⇒ ElementConfig
constructor
A new instance of ElementConfig.
- #value_from_attrs(attrs) ⇒ Object
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 |
# File 'lib/sax-machine/sax_element_config.rb', line 7 def initialize(name, ) @name = name.to_s if .has_key?(:with) # for faster comparisons later @with = [:with].to_a.flatten.collect {|o| o.to_s} else @with = nil end if .has_key?(:value) @value = [:value].to_s else @value = nil end @as = [:as] @collection = [:collection] if @collection @setter = "add_#{[:as]}" else @setter = "#{@as}=" end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/sax-machine/sax_element_config.rb', line 5 def name @name end |
#setter ⇒ Object (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
37 38 39 40 41 42 43 |
# File 'lib/sax-machine/sax_element_config.rb', line 37 def attrs_match?(attrs) if @with @with == (@with & attrs) else true end end |
#collection? ⇒ Boolean
49 50 51 |
# File 'lib/sax-machine/sax_element_config.rb', line 49 def collection? @collection end |
#has_value_and_attrs_match?(attrs) ⇒ Boolean
45 46 47 |
# File 'lib/sax-machine/sax_element_config.rb', line 45 def has_value_and_attrs_match?(attrs) !@value.nil? && attrs_match?(attrs) end |
#value_from_attrs(attrs) ⇒ Object
33 34 35 |
# File 'lib/sax-machine/sax_element_config.rb', line 33 def value_from_attrs(attrs) attrs[attrs.index(@value) + 1] end |