Class: Biblioteque::Model
- Inherits:
-
Object
- Object
- Biblioteque::Model
- Defined in:
- lib/biblioteque/model.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Model
constructor
A new instance of Model.
- #save_to_file(path, data = {}) ⇒ Object
- #search(filter) ⇒ Object
- #to_hash ⇒ Object
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_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/biblioteque/model.rb', line 3 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/biblioteque/model.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/biblioteque/model.rb', line 3 def name @name end |
Class Method Details
.generate_id ⇒ Object
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_hash ⇒ Object
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 |