Sha256: 28c1a72e43b873b1e7948ca99074cbbfbd135135a0a7354034ad4875bc7ed8b2

Contents?: true

Size: 746 Bytes

Versions: 3

Compression:

Stored size: 746 Bytes

Contents

module Booklist
  class Book < ActiveRecord::Base
    has_many :taggings
    has_many :tags, through: :taggings #, source: "book_id"
    validates :title, presence: true

    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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
booklist-0.0.10 lib/booklist/book.rb
booklist-0.0.9 lib/booklist/book.rb
booklist-0.0.7 lib/booklist/book.rb