Class: Biblioteque::Library

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

Instance Attribute Summary collapse

Attributes inherited from Model

#created_at, #id, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

generate_id, #save_to_file, #to_hash

Constructor Details

#initialize(params = {}) ⇒ Library

Returns a new instance of Library.



16
17
18
19
20
# File 'lib/biblioteque/library.rb', line 16

def initialize(params = {})
	super
	@items = []
	@to_hash_params = [:id, :name, :updated_at, :created_at, :db_id, :items]
end

Instance Attribute Details

#db_idObject

Returns the value of attribute db_id.



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

def db_id
  @db_id
end

#updated_atObject

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

Class Method Details

.create(name, db_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/biblioteque/library.rb', line 5

def self.create(name, db_id)
	raise "No" unless name
	lib = self.new
	lib.id = generate_id
	lib.name = name
	lib.db_id = db_id
	lib.created_at = Time.now
	lib.updated_at = Time.now
	lib
end

Instance Method Details

#add(path) ⇒ Object



43
44
45
46
47
48
# File 'lib/biblioteque/library.rb', line 43

def add(path)   
	raise "No" unless path
	crawler = Crawler.new(path)
	@items = @items | crawler.search_for_library(id)
	true
end

#filesObject



39
40
41
# File 'lib/biblioteque/library.rb', line 39

def files
	@items.select{|i| i[:file] == true}
end

#foldersObject



35
36
37
# File 'lib/biblioteque/library.rb', line 35

def folders
	@items.select{|i| i[:file] == false}
end

#itemsObject



22
23
24
# File 'lib/biblioteque/library.rb', line 22

def items
	@items
end

#search(filter) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/biblioteque/library.rb', line 50

def search(filter)
	return nil unless filter
	filter.downcase!
	items.select do |i|
		i[:path].downcase.index(filter) || 
		i[:name].downcase.index(filter) ||
		i[:id] == filter
	end
end

#statObject



26
27
28
29
30
31
32
33
# File 'lib/biblioteque/library.rb', line 26

def stat
	puts "#Library #{name} status#"
	puts " created at: #{created_at}"
	puts " updated at: #{updated_at}"
	puts " items: #{self.items.size}"
	puts " folders: #{folders.size}"
	puts " files: #{files.size}"
end