Class: Timelog::Book::Clients
- Inherits:
-
Object
- Object
- Timelog::Book::Clients
- Defined in:
- lib/timelog/book/clients.rb
Instance Method Summary collapse
- #add(name, shortcut = nil) ⇒ Object
- #exists?(client) ⇒ Boolean
- #id(client) ⇒ Object
-
#initialize(book) ⇒ Clients
constructor
A new instance of Clients.
- #name(client) ⇒ Object
Constructor Details
#initialize(book) ⇒ Clients
Returns a new instance of Clients.
4 5 6 |
# File 'lib/timelog/book/clients.rb', line 4 def initialize(book) @book = book end |
Instance Method Details
#add(name, shortcut = nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/timelog/book/clients.rb', line 8 def add(name, shortcut = nil) raise ClientExistsError if exists? name or (shortcut and exists? shortcut) @book.database.execute("insert into clients (name, shortcut) values(?, ?)", [name, shortcut]) @book.database.first_value("select id from clients order by id desc limit 1") end |
#exists?(client) ⇒ Boolean
14 15 16 |
# File 'lib/timelog/book/clients.rb', line 14 def exists?(client) @book.database.first_value("select id from clients where id = ? or name = ? or shortcut = ?", [client, client, client]) end |
#id(client) ⇒ Object
23 24 25 26 |
# File 'lib/timelog/book/clients.rb', line 23 def id(client) raise ClientNotFoundError unless exists? client @book.database.first_value("select id from clients where id = ? or name = ? or shortcut = ?", [client, client, client]) end |
#name(client) ⇒ Object
18 19 20 21 |
# File 'lib/timelog/book/clients.rb', line 18 def name(client) raise ClientNotFoundError unless exists? client @book.database.first_value("select name from clients where id = ? or name = ? or shortcut = ?", [client, client, client]) end |