Sha256: bc72e10a7b1e1f2aa37edc3d49e232853ce3208739557984c2592b45c1cae92e

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require "pandoc_object_filters"

module PandocObjectFilters
  module V1_16
    module Element
      class Base
        attr_accessor :contents

        def self.contents_attr(name, index = nil)
          if index
            define_method(name) { contents[index] }
            define_method("#{name}=") { |value| contents[index] = value }
          else
            define_method(name) { contents }
            define_method("#{name}=") { |value| @contents = value }
          end
        end

        def initialize(contents = [])
          @contents = contents
          convert_contents if respond_to?(:convert_contents, true)
        end

        def to_ast
          PandocObjectFilters::Element.to_ast(contents)
        end

        def inspect
          to_ast.inspect
        end

        def ==(other)
          self.class == other.class && contents == other.contents
        end

        def walk(&block)
          PandocObjectFilters::Element.walk(self, &block)
        end

        def walk!(&block)
          PandocObjectFilters::Element.walk!(self, &block)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pandoc_object_filters-0.2.0 lib/pandoc_object_filters/v1_16/element/base.rb