Sha256: ad62df127ee1fdf612a0493099b623d8fa6df3c9663ef728c941d5548cfb99fc

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Danica
  module Common
    extend ::ActiveSupport::Concern
    included do
      include Wrapper
      include DSL

      default_values :constant?, :signaled?, :container?, :variable?,
                     :variable_holder?, false
      default_value  :priority, 1
    end

    class_methods do
      def default_value(name, value)
        define_method(name) { |*_| value }
      end

      def default_values(*names, value)
        names.each do |name|
          default_value(name, value)
        end
      end
    end

    def to_f
      raise Exception::NotImplemented
    end

    def to_tex(**options)
      to(:tex, options)
    end

    def to_gnu(**options)
      to(:gnu, options)
    end

    def to(format, **options)
      case format.to_sym
      when :tex
        to_tex(options)
      when :gnu
        to_gnu(options)
      when :f
        to_f
      else
        raise Exception::FormattedNotFound
      end
    end

    def tex(**options)
      formatted(format: :tex, **options)
    end

    def gnu(**options)
      formatted(format: :gnu, **options)
    end

    def formatted(*args)
      Formatted.new(self, *args)
    end

    def valued?
      to_f.present?
    rescue Exception::NotDefined
      false
    end

    def content
      self
    end

    private

    def wrap_as_group(value)
      return value if is_grouped? || value.priority >= priority
      group(value)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danica-2.7.5 lib/danica/common.rb