Class: Bookscan::Groups

Inherits:
Array
  • Object
show all
Defined in:
lib/bookscan/groups.rb

Instance Method Summary collapse

Instance Method Details

#book(book_id) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/bookscan/groups.rb', line 46

def book(book_id)
  g = find do |g|
     g.books.has?(book_id)
  end
  return nil unless g
  g.books.by_id(book_id)
end

#by_hash(hash) ⇒ Object



16
17
18
19
20
# File 'lib/bookscan/groups.rb', line 16

def by_hash(hash)
  i = to_index(hash)
  return nil unless i
  at(i)
end

#hashesObject



8
9
10
11
12
13
14
# File 'lib/bookscan/groups.rb', line 8

def hashes
  h = Array.new
  each do |group|
    h << group.hash
  end
  h
end

#to_index(hash) ⇒ Object



22
23
24
25
26
27
# File 'lib/bookscan/groups.rb', line 22

def to_index(hash)
  each_index do |i|
    return i if hash == at(i).hash
  end
  nil
end

#to_sObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bookscan/groups.rb', line 29

def to_s
  table = Mutter::Table.new(:delimiter => '|') do
    column :style => :green
    column
    column
    column
    column
    column
  end
  # table << ["#","Date","num","price","status"]

  sort{ |a,b| a.date <=> b.date}.each do |group|
    table << group.to_a
  end
  table.to_s if length > 0
end