class Yinx::SQL::Batch

Public Class Methods

insert(notes) click to toggle source
# File lib/yinx_sql/batch.rb, line 11
def self.insert notes
  batch = Batch.new

  tags = Hash.new do |h, name|
    tag = Tag.new name: name
    batch.tags << tag
    h[name] = tag
  end

  notes.each do |note|
    n = Note.new(title: note.title,
                 book: note.book,
                 stack: note.stack,
                 content_length: note.contentLength,
                 created_at: note.created_at,
                 updated_at: note.updated_at)

    batch.notes << n

    note.tags.each do |tag_name|
      tag = tags[tag_name]
      tag.notes << n
    end
  end

  batch.save
end

Public Instance Methods

books() click to toggle source
# File lib/yinx_sql/batch.rb, line 39
def books
  notes.map(&:stack_book).uniq
end
stacks() click to toggle source
# File lib/yinx_sql/batch.rb, line 43
def stacks
  notes.map{|note| note.stack.nil? ? 'NO_STACK' : note.stack}.uniq
end