Sha256: 8406b1c29cd307237fb741d93bfa33341a582dca7dca2038dd80db8aad30b0a1

Contents?: true

Size: 989 Bytes

Versions: 4

Compression:

Stored size: 989 Bytes

Contents

# frozen_string_literal: true

module Evertils
  module Action
    class DuplicatePrevious < Action::Base
      def initialize(args)
        super(args)

        @args[:content] = find_previous(args)

        query = Evertils::Common::Query::Simple.new
        query.create_note_from_hash(@args)
      end

      private

      def find_previous(args)
        day = Date.today
        note = nil

        Notify.info("Searching for last #{@args[:notebook]}...")

        (1..Evertils::Type::Base::MAX_SEARCH_SIZE).each do |iter|
          day -= 1
          dow = day.strftime('%a')

          # always skip weekends, even if there is a note for those days
          next if %i[Sat Sun].include?(dow)

          note_title = @args[:title]
          note = @note_helper.model.find_note_contents(note_title).entity

          Notify.info(" (#{iter}) #{note_title}")

          break unless note.nil?
        end

        @api.convert_to_xml(note.content).prepare
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
evertils-1.0.5 lib/evertils/actions/duplicate_previous.rb
evertils-1.0.4 lib/evertils/actions/duplicate_previous.rb
evertils-1.0.3 lib/evertils/actions/duplicate_previous.rb
evertils-1.0.2 lib/evertils/actions/duplicate_previous.rb