Sha256: 01c2248618a1dfc53c625d8edebef3918100c0c15ed0a4c7501ebf3f21c42f03

Contents?: true

Size: 1.43 KB

Versions: 7

Compression:

Stored size: 1.43 KB

Contents

require 'yinx/version'
require 'yinx/user_store'
require 'yinx/down_config'
require 'yinx/note_meta'
require 'yinx/note_store'

module Yinx

  Ex_Result = [:includeDeleted, :includeUpdateSequenceNum,
		   :includeAttributes, :includeLargestResourceMime,
                   :includeLargestResourceSize]

  Result = (NoteStore::NOTE_META_RESULT_SPECS - Ex_Result).reduce({}) do |hash, attr_present|
    hash[attr_present] = true; hash
  end

  class << self

    attr_reader :config

    def fetch real = true, &block
      @real = real
      @config = DownConfig.new note_store
      config.instance_eval &block
      download
    end

    def fetch_all
      fetch {book /./}
    end

    private

    def download
      config.note_filters.map do |filter|
	note_store.findNotes(filter.merge Result)
      end.flatten.map do |note|
	NoteMeta.new note, note_store
      end
    end

    def note_store
      @note_store ||= UserStore.new(@real).note_store
    end

    def formated book, meta
      address = book.stack ? "#{book.stack}/#{book.name}/#{meta.title}" : "#{book.name}/#{meta.title}"
      time = Time.at(meta.updated / 1000).strftime('%F %T')
      "#{meta.updated} #{time} #{address}"
    end

    def concat_metas real
      books = note_store(real).listNotebooks &block
      books.map do |book|
	metas = note_store.findNotes({notebookGuid: book.guid}).notes
	metas.map do |meta|
	  "#{formated book, meta}\n"
	end.join
      end.join
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
yinx-0.1.6 lib/yinx.rb
yinx-0.1.5 lib/yinx.rb
yinx-0.1.4 lib/yinx.rb
yinx-0.1.3 lib/yinx.rb
yinx-0.1.2 lib/yinx.rb
yinx-0.1.1 lib/yinx.rb
yinx-0.1.0 lib/yinx.rb