Sha256: 32e091e6c09d369ac11f14e4d75c3979e07419f89f62323f5f96a21ec67c351f

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Evertils
  module Type
    class Base
      attr_reader :title, :content, :notebook

      COLOUR = 0xffffff

      #
      # @since 0.3.7
      def initialize(config, *args)
        @model = Evertils::Common::Query::Simple.new
        @format = Evertils::Helper.load('Formatting')
        @config = config if config
        @args = args unless args.size.zero?
      end

      #
      # @since 0.3.7
      def create
        data = {
          title: @title,
          body: @content,
          parent_notebook: self.class::NOTEBOOK,
          tags: tags || [],
          colour: self.class::COLOUR
        }

        raise 'Invalid title' if @title.nil?
        raise 'Invalid note content' if @content.nil?
        raise 'Invalid notebook' if self.class::NOTEBOOK.nil?

        @model.create_note(data)
      end

      #
      # @since 0.3.7
      def should_create?
        note_title = @format.date_templates[self.class::NOTEBOOK]
        found = @model.find_note_contents(note_title)
        result = found.entity.nil?

        Notify.warning "#{self.class.name} skipped, note already exists" unless result

        result
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
evertils-0.3.14.1 lib/evertils/type.rb
evertils-0.3.14 lib/evertils/type.rb
evertils-0.3.13 lib/evertils/type.rb
evertils-0.3.12 lib/evertils/type.rb