Sha256: 7b0851d04583ed47f774f95fc44a7b0a0773aa1ab2a97b4232464a50315efeda

Contents?: true

Size: 836 Bytes

Versions: 2

Compression:

Stored size: 836 Bytes

Contents

# frozen_string_literal: true

class Danica::Formatted
  attr_reader :content, :options

  def initialize(content, **options)
    @content = content
    @options = options
  end

  def to_s
    content.to(format, options)
  end

  def ==(other)
    return false unless other.class == self.class

    other.content == content &&
      other.format == format
  end

  def format
    options[:format]
  end

  def repack(object)
    self.class.new(
      object,
      options
    )
  end

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

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

  def to(format, **opts)
    content.to(format, options.merge(opts))
  end

  private

  def method_missing(method, *args)
    value = content.public_send(method, *args)
    return value unless value.is_a?(Danica::Common)

    repack(value)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
danica-2.7.7 lib/danica/formatted.rb
danica-2.7.6 lib/danica/formatted.rb