Sha256: ba37337b111180e58445497e72a8302a91df111a97c0ecc86143d6d613c9a757

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

module ENUtils
  class Notebook < Evernote::EDAM::Type::Notebook

     # Evernote::EDAM::Type::Notebook fields
     #   guid:"afa4ba59-xxxx-42ed-xxxx-zzzzzzzzzzzz"
     #   name:"Books"
     #   updateSequenceNum:24108
     #   defaultNotebook:false
     #   serviceCreated:1297607548000
     #   serviceUpdated:1387262389000
     #   restrictions:<Evernote::EDAM::Type::NotebookRestrictions ...>

      attr_reader :guid, :name, :updateSequenceNum, :defaultNotebook, :serviceCreated, :serviceUpdated, :restrictions

    def initialize(core, edam_notebook)
      @core              = core
      @guid              = edam_notebook.guid
      @name              = edam_notebook.name
      @updateSequenceNum = edam_notebook.updateSequenceNum
      @defaultNotebook   = edam_notebook.defaultNotebook
      @serviceCreated    = Time.at(edam_notebook.serviceCreated/1000)
      @serviceUpdated    = Time.at(edam_notebook.serviceUpdated/1000)
      @restrictions      = edam_notebook.restrictions
    end

    def notes(options={})
      Note.where(@core, options.merge(notebook: self))
    end

    def self.find_by_guid(core, guid)
      notebook = core.notestore.listNotebooks(core.token).find{|nb| nb.guid == guid }
      notebook.present? ? new(core, notebook) : nil
    end

    def self.find_by_name(core, name)
      notebook = core.notestore.listNotebooks(core.token).find{|nb| nb.name.downcase == name.to_s.downcase }
      notebook.present? ? new(core, notebook) : nil
    end

    def self.where(core, options={})
      notebooks = core.notestore.listNotebooks(core.token).map{|nb| new(core, nb) }
      return notebooks if options.empty?
      case options[:name]
      when String
        notebooks.select{|nb| options[:name].downcase == nb.name.downcase }
      when Regexp
        notebooks.select{|nb| options[:name] =~ nb.name }
      else
        notebooks
      end
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
evernote_utils-0.1.3 lib/evernote_utils/notebook.rb
evernote_utils-0.1.2 lib/evernote_utils/notebook.rb
evernote_utils-0.1.1 lib/evernote_utils/notebook.rb
evernote_utils-0.1.0 lib/evernote_utils/notebook.rb
evernote_utils-0.0.9 lib/evernote_utils/notebook.rb
evernote_utils-0.0.4 lib/evernote_utils/notebook.rb