Sha256: 19a70c2a9cf854cbeedc6dedf6d41a091bb60a457d350c2b65ed035dbe9aeb73

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module Thinreports
  module Layout
    class Base
      EXT_NAME = 'tlf'
      include Utils

      class << self
        # @param [String] filename
        # @return [Thinreports::Layout::Format]
        # @raise [Thinreports::Errors::InvalidLayoutFormat]
        # @raise [Thinreports::Errors::IncompatibleLayoutFormat]
        def load_format(filename)
          filename += ".#{EXT_NAME}" unless filename =~ /\.#{EXT_NAME}$/

          raise Thinreports::Errors::LayoutFileNotFound unless File.exist?(filename)
          # Build format.
          Thinreports::Layout::Format.build(filename)
        end
      end

      attr_reader :format

      # @return [String]
      attr_reader :filename

      # @return [Symbol]
      attr_reader :id

      # @param [String] filename
      # @param [Hash] options
      # @option options [Symbol] :id (nil)
      def initialize(filename, options = {})
        @filename = filename
        @format = self.class.load_format(filename)
        @id = options[:id]
      end

      # @return [Boolean] Return the true if is default layout.
      def default?
        @id.nil?
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thinreports-0.12.1 lib/thinreports/layout/base.rb
thinreports-0.12.0 lib/thinreports/layout/base.rb
thinreports-0.11.0 lib/thinreports/layout/base.rb