Class: Audrey::Node::Array
- Inherits:
-
Collection
- Object
- Audrey::Node
- Collection
- Audrey::Node::Array
- Defined in:
- lib/audrey.rb
Overview
Audrey::Node::Array
Instance Attribute Summary
Attributes inherited from Audrey::Node
Class Method Summary collapse
-
.new_object ⇒ Object
————————————————————————— new_object.
Instance Method Summary collapse
-
#[](idx) ⇒ Object
————————————————————————— [].
-
#[]=(key, child) ⇒ Object
————————————————————————— []=.
-
#attach_to(arr) ⇒ Object
————————————————————————— attach_to.
-
#each ⇒ Object
————————————————————————— each.
- #each_with_index ⇒ Object
-
#include?(val) ⇒ Boolean
————————————————————————— include? NOTE: This routine could probably be better implemented by the database engine.
-
#push(child) ⇒ Object
————————————————————————— push.
-
#to_array ⇒ Object
————————————————————————— to_array.
Methods inherited from Collection
#any?, #changed, #changed=, #child_pks, #clear, create_object, #length
Methods inherited from Audrey::Node
#alive?, #ancestors, #delete_object, #fco, #initialize, #isolate, #row
Constructor Details
This class inherits a constructor from Audrey::Node
Class Method Details
.new_object ⇒ Object
new_object
1164 1165 1166 |
# File 'lib/audrey.rb', line 1164 def self.new_object return([]) end |
Instance Method Details
#[](idx) ⇒ Object
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
# File 'lib/audrey.rb', line 1175 def [](idx) read_check() row = @engine.row_by_array_index(@pk, idx) # if we got a hash if row return @db.object_from_row(row) # else return nil else return nil end end |
#attach_to(arr) ⇒ Object
attach_to
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 |
# File 'lib/audrey.rb', line 1306 def attach_to(arr) # hold on to original values orgs = arr.clone # audrey() def arr.audrey(p_node = nil) if p_node @audrey_node = p_node end # return return @audrey_node end # NOTE: There must be a simpler way to delegate all these hash methods # to @audrey_node # [] def arr.[](idx) return @audrey_node[idx] end # push def arr.push(val) return @audrey_node.push(val) end # each def arr.each() if block_given? @audrey_node.each do |k, v| yield k, v end else return @audrey_node.each end end # each_with_index def arr.each_with_index() @audrey_node.each_with_index do |el, idx| yield el, idx end end # length def arr.length() return @audrey_node.length end # any? def arr.any?() return @audrey_node.any? end # clear def arr.clear() return @audrey_node.clear() end # join def arr.join(sep) rv = [] @audrey_node.each do |el| rv.push el end return rv.join(sep) end # include? def arr.include?(val) return @audrey_node.include?(val) end # initial call to audrey object arr.audrey self # save child elements orgs.each do |v| arr.push v end end |
#each ⇒ Object
each
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
# File 'lib/audrey.rb', line 1219 def each # $tm.hrm read_check() rv = nil # loop through rows @engine.array_each(@pk) do |row| obj = @db.object_from_row(row) if block_given? yield obj else rv ||= [] rv.push obj end end # return return rv end |
#each_with_index ⇒ Object
1240 1241 1242 1243 1244 1245 1246 1247 |
# File 'lib/audrey.rb', line 1240 def each_with_index idx = 0 each do |el| yield el, idx idx += 1 end end |
#include?(val) ⇒ Boolean
include? NOTE: This routine could probably be better implemented by the database engine. For now just doing it the brute force way.
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 |
# File 'lib/audrey.rb', line 1275 def include?(val) # $tm.hrm # if val has a audrey object if val.respond_to?('audrey') each do |object| if object.respond_to?('audrey') if val.audrey.pk == object.audrey.pk return true end end end else each do |object| if val === object return true end end end # didn't find it return false end |
#push(child) ⇒ Object
push
1206 1207 1208 1209 1210 |
# File 'lib/audrey.rb', line 1206 def push(child) write_check() save_child child return child end |
#to_array ⇒ Object
to_array
1256 1257 1258 1259 1260 1261 1262 1263 1264 |
# File 'lib/audrey.rb', line 1256 def to_array rv = [] each do |el| rv.push el end return rv end |