Sha256: 4815c3ba2160d492b606fb92a2ff307281df2df52c5405511ed21df18a88c927

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# encoding: utf-8
module Infoboxer
  module Tree
    # Represents image (or other media file).
    #
    # See [Wikipedia Tutorial](https://en.wikipedia.org/wiki/Wikipedia:Extended_image_syntax)
    # for explanation of attributes.
    class Image < Node
      def initialize(path, params = {})
        @caption = params.delete(:caption)
        super({path: path}.merge(params))
      end

      # Image caption. Can have (sometimes many) other nodes inside.
      #
      # @return [Nodes]
      attr_reader :caption

      # @!attribute [r] path 
      # @!attribute [r] type
      # @!attribute [r] location 
      # @!attribute [r] alignment
      # @!attribute [r] link
      # @!attribute [r] alt 

      def_readers :path, :type,
        :location, :alignment, :link,
        :alt

      def border?
        !params[:border].to_s.empty?
      end

      def width
        params[:width].to_i
      end

      def height
        params[:height].to_i
      end

      def to_tree(level = 0)
        super(level) +
          if caption && !caption.empty?
            indent(level+1) + "caption:\n" +
              caption.map(&call(to_tree: level+2)).join
          else
            ''
          end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
infoboxer-0.1.1 lib/infoboxer/tree/image.rb
infoboxer-0.1.0 lib/infoboxer/tree/image.rb