Class: SimplerDB::Item
- Inherits:
-
Object
- Object
- SimplerDB::Item
- Defined in:
- lib/simplerdb/db.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #delete_attribute(attr) ⇒ Object
- #get_attributes(attribute_name = nil) ⇒ Object
-
#initialize(name) ⇒ Item
constructor
A new instance of Item.
- #put_attribute(attr, replace = false) ⇒ Object
Constructor Details
#initialize(name) ⇒ Item
Returns a new instance of Item.
18 19 20 21 |
# File 'lib/simplerdb/db.rb', line 18 def initialize(name) @name = name @attributes = Hash.new { |hash, key| hash[key] = [] } end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
16 17 18 |
# File 'lib/simplerdb/db.rb', line 16 def attributes @attributes end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/simplerdb/db.rb', line 16 def name @name end |
Instance Method Details
#delete_attribute(attr) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/simplerdb/db.rb', line 28 def delete_attribute(attr) if attr.value.nil? @attributes[attr.name].clear else @attributes[attr.name].delete(attr) end if @attributes[attr.name].size == 0 @attributes.delete(attr.name) end end |
#get_attributes(attribute_name = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/simplerdb/db.rb', line 40 def get_attributes(attribute_name = nil) attrs = [] @attributes.each do |key, value| if (attribute_name.nil? || attribute_name == key) attrs += value end end return attrs end |
#put_attribute(attr, replace = false) ⇒ Object
23 24 25 26 |
# File 'lib/simplerdb/db.rb', line 23 def put_attribute(attr, replace = false) @attributes[attr.name].clear if replace @attributes[attr.name] << attr end |