Sha256: da82bfdf874982b1f255f02f48431fca479239c3da3bb5644818532ab331ace0

Contents?: true

Size: 978 Bytes

Versions: 2

Compression:

Stored size: 978 Bytes

Contents

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

      #
      # @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 || []
        }

        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[NOTEBOOK]
        found = @model.find_note_contents(note_title)

        found.entity.nil?
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
evertils-0.3.10 lib/evertils/type.rb
evertils-0.3.9 lib/evertils/type.rb