Class: SAXMachine::SAXConfig::ElementConfig
- Inherits:
-
Object
- Object
- SAXMachine::SAXConfig::ElementConfig
- Defined in:
- lib/sax-machine/config/sax_element.rb
Instance Attribute Summary collapse
-
#as ⇒ Object
readonly
Returns the value of attribute as.
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#data_class ⇒ Object
readonly
Returns the value of attribute data_class.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#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_and_attrs_match?(attrs) ⇒ Boolean
-
#initialize(name, options) ⇒ ElementConfig
constructor
A new instance of ElementConfig.
- #required? ⇒ Boolean
- #to_s ⇒ Object
- #value_configured? ⇒ Boolean
- #value_from_attrs(attrs) ⇒ Object
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 |
# File 'lib/sax-machine/config/sax_element.rb', line 6 def initialize(name, ) @name = name.to_s @with = .fetch(:with, {}) @value = if .has_key?(:value) [:value].to_s else nil end @as = [:as] @collection = [:collection] @default = [:default] @setter = if @collection "add_#{[:as]}" else "#{@as}=" end @data_class = [:class] @required = [:required] end |
Instance Attribute Details
#as ⇒ Object (readonly)
Returns the value of attribute as.
4 5 6 |
# File 'lib/sax-machine/config/sax_element.rb', line 4 def as @as end |
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
4 5 6 |
# File 'lib/sax-machine/config/sax_element.rb', line 4 def collection @collection end |
#data_class ⇒ Object (readonly)
Returns the value of attribute data_class.
4 5 6 |
# File 'lib/sax-machine/config/sax_element.rb', line 4 def data_class @data_class end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
4 5 6 |
# File 'lib/sax-machine/config/sax_element.rb', line 4 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/sax-machine/config/sax_element.rb', line 4 def name @name end |
#setter ⇒ Object (readonly)
Returns the value of attribute setter.
4 5 6 |
# File 'lib/sax-machine/config/sax_element.rb', line 4 def setter @setter end |
Instance Method Details
#attrs_match?(attrs) ⇒ Boolean
50 51 52 53 54 |
# File 'lib/sax-machine/config/sax_element.rb', line 50 def attrs_match?(attrs) @with.all? do |key, value| value === attrs[key.to_s] end end |
#collection? ⇒ Boolean
60 61 62 |
# File 'lib/sax-machine/config/sax_element.rb', line 60 def collection? !!@collection end |
#column ⇒ Object
38 39 40 |
# File 'lib/sax-machine/config/sax_element.rb', line 38 def column @as || @name.to_sym end |
#has_value_and_attrs_match?(attrs) ⇒ Boolean
56 57 58 |
# File 'lib/sax-machine/config/sax_element.rb', line 56 def has_value_and_attrs_match?(attrs) !@value.nil? && attrs_match?(attrs) end |
#required? ⇒ Boolean
42 43 44 |
# File 'lib/sax-machine/config/sax_element.rb', line 42 def required? !!@required end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/sax-machine/config/sax_element.rb', line 34 def to_s "name: #{@name} dataclass: #{@data_class} setter: #{@setter} required: #{@required} value: #{@value} as:#{@as} collection: #{@collection} with: #{@with}" end |
#value_configured? ⇒ Boolean
30 31 32 |
# File 'lib/sax-machine/config/sax_element.rb', line 30 def value_configured? !@value.nil? end |
#value_from_attrs(attrs) ⇒ Object
46 47 48 |
# File 'lib/sax-machine/config/sax_element.rb', line 46 def value_from_attrs(attrs) attrs.fetch(@value, nil) end |