Sha256: 79556e5240b653cf34e1c34bc767801bd43db6c6c670f8684779991aa68b6479

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

module Evertils
  module Type
    class Daily < Type::Base
      NOTEBOOK = :Daily
      COLOUR = 0xffe8b7

      #
      # @since 0.3.7
      def initialize(config, *args)
        super(config, *args)

        @title = @format.date_templates[NOTEBOOK]
        @content = @format.template_contents(NOTEBOOK)

        attach_pq_note if morning_note?
      end

      #
      # @since 0.3.9
      def tags
        [
          "day-#{Date.today.yday}",
          "week-#{Date.today.cweek}",
          "month-#{Date.today.month}"
        ]
      end

      private

      #
      # TODO: refactor
      # @since 0.3.13
      def attach_pq_note
        enml = @api.from_str(@format.template_contents(NOTEBOOK))
        pq = @note_helper.wait_for(:'Priority Queue')
        xml_conf = {
          href: @note_helper.internal_url_for(pq.entity),
          content: @format.date_templates[:'Priority Queue']
        }
        xml = Evertils::Helper.load('Xml', enml)
        a = xml.create(:a, xml_conf)

        enml.at('li:contains("Queue") ul li').children.first.replace(a)

        # remove dtd if it is the first element
        if enml.children.first.is_a?(Evertils::Helper::DTD)
          enml.children.first.remove
        end

        @content = enml
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
evertils-1.0.0 lib/evertils/types/daily.rb
evertils-0.4.0 lib/evertils/types/daily.rb
evertils-0.3.27 lib/evertils/types/daily.rb