Class: Locomotive::RelationalAlgebra::Schema
- Inherits:
-
Object
- Object
- Locomotive::RelationalAlgebra::Schema
- Includes:
- XML
- Defined in:
- lib/locomotive/relational_algebra/schema.rb
Overview
The Schema contains the attributes and its associated types. Each operator of the relational algebra contains a schema.
Instance Method Summary collapse
-
#+(schm) ⇒ Object
merges two schemas, given that there are no duplicate keys.
- #[]=(attr, types) ⇒ Object
- #attributes ⇒ Object
- #attributes?(attributes) ⇒ Boolean
- #clone ⇒ Object
-
#initialize(hash) ⇒ Schema
constructor
A new instance of Schema.
- #inspect ⇒ Object
- #to_xml ⇒ Object
Methods included from XML
Constructor Details
#initialize(hash) ⇒ Schema
Returns a new instance of Schema.
33 34 35 |
# File 'lib/locomotive/relational_algebra/schema.rb', line 33 def initialize(hash) self.schema = hash end |
Instance Method Details
#+(schm) ⇒ Object
merges two schemas, given that there are no duplicate keys
48 49 50 51 52 53 54 55 56 |
# File 'lib/locomotive/relational_algebra/schema.rb', line 48 def +(schm) if duplicates?(schm) raise Duplicates, "Found duplicates in #{self.attributes} " \ "and #{schm.attributes}." end # create a new schema Schema.new(schema.merge(schm.schema)) end |
#[]=(attr, types) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/locomotive/relational_algebra/schema.rb', line 59 def []=(attr,types) raise Duplicates, "#{attr.inspect} results in duplicates " \ "in schema #{self.attributes}" unless self[attr].nil? schema[attr] = types end |
#attributes ⇒ Object
37 38 39 |
# File 'lib/locomotive/relational_algebra/schema.rb', line 37 def attributes schema.keys end |
#attributes?(attributes) ⇒ Boolean
41 42 43 |
# File 'lib/locomotive/relational_algebra/schema.rb', line 41 def attributes?(attributes) attributes.all? { |attr| self.attributes.member? attr } end |
#clone ⇒ Object
80 81 82 |
# File 'lib/locomotive/relational_algebra/schema.rb', line 80 def clone Schema.new( self.schema.clone ) end |
#inspect ⇒ Object
76 77 78 |
# File 'lib/locomotive/relational_algebra/schema.rb', line 76 def inspect "<Schema [#{schema.map { |s| s.inspect }.join(", ")}]>" end |
#to_xml ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/locomotive/relational_algebra/schema.rb', line 67 def to_xml _schema_ do self.schema.collect do |attr,types| col :name => attr.to_xml, :type => types.collect { |ty| ty.to_xml }.join(",") end.join end end |