Class: Hash

Inherits:
Object show all
Defined in:
lib/basic/basic.rb

Overview

def add x end end

Direct Known Subclasses

RuleSet

Instance Method Summary collapse

Instance Method Details

#create_path(*path) ⇒ Object


169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/basic/basic.rb', line 169

def create_path *path
	entry = self
	endcap = path.pop
	final = path.pop

	path.each { |e|
		if !entry[e] then entry[e] = {} end
		entry = entry[e]
	}

	if !entry[final] then entry[final] = endcap end
end

#defaults(defs) ⇒ Object


140
141
142
143
144
145
146
147
# File 'lib/basic/basic.rb', line 140

def defaults defs
	defs.assert_type Hash

	keyset = keys
	defs.each { |k, v|
		if !keyset.include? k then self[k] = v end
	}
end

#prep_insert(table) ⇒ Object


149
150
151
152
153
154
155
156
157
# File 'lib/basic/basic.rb', line 149

def prep_insert table
	set = []

	each { |k, v|
		set = "( #{k}, #{v} )"
	}

	set = "insert into #{table} values ( #{set.join ','} ),"
end

#required(*elements) ⇒ Object


182
183
184
185
186
# File 'lib/basic/basic.rb', line 182

def required *elements
	elements.each { |element|
		assert has_key?( element ), "required key missing: #{element}"
	}
end

#select(*items) ⇒ Object


159
160
161
162
163
164
165
166
167
# File 'lib/basic/basic.rb', line 159

def select *items
	r = {}

	items.each { |item|
		r[item] = self[item]
	}

	r
end