Class: SAXMachine::SAXConfig::ElementConfig
- Inherits:
-
Object
- Object
- SAXMachine::SAXConfig::ElementConfig
- Defined in:
- lib/sax-machine/sax_element_config.rb
Instance Attribute Summary collapse
-
#data_class ⇒ Object
readonly
Returns the value of attribute data_class.
-
#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
- #column ⇒ Object
- #has_value? ⇒ Boolean
- #has_value_and_attrs_match?(attrs) ⇒ Boolean
-
#initialize(name, options) ⇒ ElementConfig
constructor
A new instance of ElementConfig.
- #required? ⇒ Boolean
- #value_from_attrs(attrs) ⇒ Object
- #xmlns_match?(ns) ⇒ Boolean
Constructor Details
#initialize(name, options) ⇒ ElementConfig
Returns a new instance of ElementConfig.
6 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 34 35 36 37 38 |
# File 'lib/sax-machine/sax_element_config.rb', line 6 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 @data_class = [:class] @required = [:required] @xmlns = case [:xmlns] when Array then [:xmlns] when String then [[:xmlns]] else nil end end |
Instance Attribute Details
#data_class ⇒ Object (readonly)
Returns the value of attribute data_class.
4 5 6 |
# File 'lib/sax-machine/sax_element_config.rb', line 4 def data_class @data_class end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/sax-machine/sax_element_config.rb', line 4 def name @name end |
#setter ⇒ Object (readonly)
Returns the value of attribute setter.
4 5 6 |
# File 'lib/sax-machine/sax_element_config.rb', line 4 def setter @setter end |
Instance Method Details
#attrs_match?(attrs) ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sax-machine/sax_element_config.rb', line 53 def attrs_match?(attrs) if @with if attrs.nil? # If no attributes, match only if the :with clause is empty. @with.empty? else # Attributes must match :with clause. attrs.include?(@with) end else true end end |
#collection? ⇒ Boolean
79 80 81 |
# File 'lib/sax-machine/sax_element_config.rb', line 79 def collection? @collection end |
#column ⇒ Object
40 41 42 |
# File 'lib/sax-machine/sax_element_config.rb', line 40 def column @as || @name.to_sym end |
#has_value? ⇒ Boolean
67 68 69 |
# File 'lib/sax-machine/sax_element_config.rb', line 67 def has_value? !@value.nil? end |
#has_value_and_attrs_match?(attrs) ⇒ Boolean
71 72 73 |
# File 'lib/sax-machine/sax_element_config.rb', line 71 def has_value_and_attrs_match?(attrs) has_value? && attrs_match?(attrs) end |
#required? ⇒ Boolean
44 45 46 |
# File 'lib/sax-machine/sax_element_config.rb', line 44 def required? @required end |
#value_from_attrs(attrs) ⇒ Object
48 49 50 51 |
# File 'lib/sax-machine/sax_element_config.rb', line 48 def value_from_attrs(attrs) pair = attrs.detect { |k, v| k == @value } pair ? pair.last : nil end |
#xmlns_match?(ns) ⇒ Boolean
75 76 77 |
# File 'lib/sax-machine/sax_element_config.rb', line 75 def xmlns_match?(ns) @xmlns.nil? || @xmlns.include?(ns) end |