Class: SAXMachine::SAXConfig::AttributeConfig

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ AttributeConfig

Returns a new instance of AttributeConfig.



7
8
9
10
11
12
13
# File 'lib/lazy-sax-machine/sax_attribute_config.rb', line 7

def initialize(name, options)
  @name = name.to_s
  @as = options[:as]
  @class = options[:class]
  @setter = "#{@as}="
  @required = options[:required]
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#setterObject (readonly)

Returns the value of attribute setter.



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

def setter
  @setter
end

Instance Method Details

#attrs_match?(attrs) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/lazy-sax-machine/sax_attribute_config.rb', line 29

def attrs_match?(attrs)
  !!attrs.assoc(@name)
end

#collection?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/lazy-sax-machine/sax_attribute_config.rb', line 37

def collection?
  false
end

#columnObject



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

def column
  @as || @name.to_sym
end

#has_value_and_attrs_match?(attrs) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/lazy-sax-machine/sax_attribute_config.rb', line 33

def has_value_and_attrs_match?(attrs)
  attrs_match?(attrs)
end

#required?Boolean

Returns:

  • (Boolean)


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

def required?
  @required
end

#value_from_attrs(attrs) ⇒ Object



23
24
25
26
27
# File 'lib/lazy-sax-machine/sax_attribute_config.rb', line 23

def value_from_attrs(attrs)
  if pair = attrs.assoc(@name)
    pair.last
  end
end