Class: Locomotive::RelationalAlgebra::ColumnStructure

Inherits:
Object
  • Object
show all
Includes:
XML
Defined in:
lib/locomotive/relational_algebra/query_information.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from XML

included, #quote

Constructor Details

#initialize(entries) ⇒ ColumnStructure

Returns a new instance of ColumnStructure.



297
298
299
300
301
# File 'lib/locomotive/relational_algebra/query_information.rb', line 297

def initialize(entries)
  @entries = entries.map do |entry|
               to_cs_entry(entry)
             end
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



288
289
290
# File 'lib/locomotive/relational_algebra/query_information.rb', line 288

def entries
  @entries
end

Instance Method Details

#-(array) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
348
349
# File 'lib/locomotive/relational_algebra/query_information.rb', line 337

def -(array)
  ColumnStructure.new(
    entries.clone.delete_if do |entry|
      case
        when AttributeColumnStructure === entry then
          array.any? { |a| entry.items.member? a }
        when OffsetType === entry
          array.member? entry.offset
        else
          raise StandardError, "Not a cs-entry"
      end
    end)
end

#[](attribute_index) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/locomotive/relational_algebra/query_information.rb', line 315

def [](attribute_index)
  # just look on the surface if you find the right attribute
  case attribute_index
    when Fixnum then
      entries[attribute_index]
    when Symbol then 
      # creating an attribute to be consistent in the signature
      attribute = Attribute.new(attribute_index)
      attr = search_by_attribute(attribute).
      attr.nil? ? nil : attr.column_structure
    when Attribute then
      attr = search_by_attribute(attribute_index)
      attr.nil? ? nil : attr.column_structure
    when Item then
      attr = search_by_attribute(attribute_index)
      attr.nil? ? nil : ColumnStructure.new([search_by_item(attribute_index)])
    else 
      raise ArgumentError, 
            "Argument should be a (Fixnum | Symbol | Attribute | Item)"
  end
end

#adaptObject



368
369
370
371
372
373
374
375
376
377
378
# File 'lib/locomotive/relational_algebra/query_information.rb', line 368

def adapt
  item_min =  self.items.min
  # we are modifying the structure
  # itself (sideeffect) so we have to
  # do a clone of it
  cs_new = self.clone
  cs_new.items.each do |it|
    it.dec!(item_min.id - 1)
  end
  cs_new
end

#add(entries) ⇒ Object Also known as: +



303
304
305
306
307
308
309
310
311
312
# File 'lib/locomotive/relational_algebra/query_information.rb', line 303

def add(entries)
  entries_ = entries

  if ColumnStructure === entries then
    entries_ = entries.entries
  end

  ColumnStructure.new(self.entries +
    entries_.map { |e| to_cs_entry(e) })
end

#cloneObject



351
352
353
354
# File 'lib/locomotive/relational_algebra/query_information.rb', line 351

def clone
  ColumnStructure.new(
    entries.map { |e| e.clone })
end

#itemsObject



356
357
358
359
360
# File 'lib/locomotive/relational_algebra/query_information.rb', line 356

def items
  entries.map do |entry|
    entry.items
  end.flatten
end

#offsetsObject



362
363
364
365
366
# File 'lib/locomotive/relational_algebra/query_information.rb', line 362

def offsets
  entries.map do |entry|
    entry.offsets
  end.flatten
end

#to_xmlObject



380
381
382
383
384
385
386
# File 'lib/locomotive/relational_algebra/query_information.rb', line 380

def to_xml
  column_structure do
    entries.collect do |e|
      e.to_xml
    end.join
  end
end