Class: Motley::AttSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/motley.rb

Overview

Motley::AttSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dfns) ⇒ AttSet


initialize



57
58
59
60
# File 'lib/motley.rb', line 57

def initialize(dfns)
	@dfns = dfns
	@vals = {}
end

Instance Attribute Details

#dfnsObject (readonly)

Returns the value of attribute dfns.



47
48
49
# File 'lib/motley.rb', line 47

def dfns
  @dfns
end

#valsObject (readonly)

Returns the value of attribute vals.



48
49
50
# File 'lib/motley.rb', line 48

def vals
  @vals
end

Instance Method Details

#[]=(key, val) ⇒ Object


[]=



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/motley.rb', line 69

def []=(key, val)
	# $tm.hrm
	
	# normalize key
	key = key.downcase
	
	# get att definition
	dfn = @dfns[key]
	
	# if no definition
	if not dfn
		exc = StandardError::Plus.new('/zax/attset/no-att-definition')
		exc['att'] = key
		raise exc
	end
	
	# XML and HTML do not have the concept of null, so if nil is assigned,
	# we delete the hash element. Else we set the value
	if val.nil?
		@vals.delete(key)
	else
		@vals[key] = dfn.set(val)
	end
end