Sha256: 233fb8871d1afea21ca3694138009b3dad8e75e3d72744cc5105de898ec44517

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

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

     # Evernote::EDAM::Type::Tag fields
     #   guid:"xxxxxxxx-xxxx-xxxx-xxxx-zzzzzzzzzzzz",
     #   name:"MyTag",
     #   updateSequenceNum:4378
    attr_reader :guid, :name, :updateSequenceNum

    def initialize(core, edam_tag)
      @core              = core
      @guid              = edam_tag.guid
      @name              = edam_tag.name
      @updateSequenceNum = edam_tag.updateSequenceNum
    end

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

    def self.find_by_guid(core, guid)
      tag = core.notestore.listTags(core.token).find{|t| t.guid == guid }
      tag.present? ? new(core, tag) : nil
    end

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

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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
evernote_utils-0.1.0 lib/evernote_utils/tag.rb
evernote_utils-0.0.9 lib/evernote_utils/tag.rb
evernote_utils-0.0.4 lib/evernote_utils/tag.rb