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
# File 'lib/lazy-sax-machine/sax_attribute_config.rb', line 7

def initialize(name, options)
  @name = name.to_s
  @as = options[:as]
  @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)


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

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

#collection?Boolean

Returns:

  • (Boolean)


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

def collection?
  false
end

#columnObject



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

def column
  @as || @name.to_sym
end

#has_value_and_attrs_match?(attrs) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#required?Boolean

Returns:

  • (Boolean)


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

def required?
  @required
end

#value_from_attrs(attrs) ⇒ Object



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

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