Class: Biblioteque::Model

Inherits:
Object
  • Object
show all
Defined in:
lib/biblioteque/model.rb

Direct Known Subclasses

Database, Library

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Model

Returns a new instance of Model.



5
6
7
8
9
# File 'lib/biblioteque/model.rb', line 5

def initialize(params = {})
   	params.each do |attr, value|
     		self.public_send("#{attr}=", value) if self.respond_to? "#{attr}="
   	end if params
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



3
4
5
# File 'lib/biblioteque/model.rb', line 3

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/biblioteque/model.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/biblioteque/model.rb', line 3

def name
  @name
end

Class Method Details

.generate_idObject



29
30
31
# File 'lib/biblioteque/model.rb', line 29

def self.generate_id
			SecureRandom.hex 
end

Instance Method Details

#save_to_file(path, data = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/biblioteque/model.rb', line 11

def save_to_file(path, data = {})
	File.open(path,"w+") do |f|
	  f.write(data.to_json)
	end
	true
end

#search(filter) ⇒ Object



25
26
27
# File 'lib/biblioteque/model.rb', line 25

def search(filter)
	raise "Not availalable for parent class"
end

#to_hashObject



18
19
20
21
22
23
# File 'lib/biblioteque/model.rb', line 18

def to_hash
	hash = {}
	return hash unless @to_hash_params
    @to_hash_params.each {|var| hash[var] = instance_variable_get("@#{var.to_s}") }
	hash
end