Class: Booklist::Book

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/booklist/book.rb

Instance Method Summary collapse

Instance Method Details

#cli_displayObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/booklist/book.rb', line 7

def cli_display
  puts "ID: #{id}\n"
  puts "Title: #{title}\n"
  puts "Author: #{author}\n" if author
  puts "Additional authors: #{addn_authors}" if addn_authors
  puts "State: #{state}" if state
  puts "Date Read: #{date_read.to_date.to_s}" if date_read
  puts "Tags: #{tag_list}\n" if tags.count > 0
  puts "\n"
end

#tag_listObject



18
19
20
21
# File 'lib/booklist/book.rb', line 18

def tag_list
  #put tags
  tags.map(&:name).join(", ")
end

#tag_list=(names) ⇒ Object



23
24
25
26
27
# File 'lib/booklist/book.rb', line 23

def tag_list=(names)
  self.tags = names.map do |n|
    Tag.where(name: n.strip).first_or_create!
  end
end