Sha256: 5a5da31d08a72d737e6e7bf47d4554bfa0aed8b2fd6d0cabae36868bcebf716f

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

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

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

            raise Thinreports::BasicReport::Errors::LayoutFileNotFound unless File.exist?(filename)
            # Build format.
            Thinreports::BasicReport::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
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thinreports-0.14.2 lib/thinreports/basic_report/layout/base.rb
thinreports-0.14.1 lib/thinreports/basic_report/layout/base.rb
thinreports-0.14.0 lib/thinreports/basic_report/layout/base.rb
thinreports-0.13.1 lib/thinreports/basic_report/layout/base.rb
thinreports-0.13.0 lib/thinreports/basic_report/layout/base.rb