Sha256: 8f26b57281415f924f7d803d5f258c0575b50db041abc570c8d68b822cd7f87c

Contents?: true

Size: 1.78 KB

Versions: 17

Compression:

Stored size: 1.78 KB

Contents

require 'caracal/core/models/base_model'


module Caracal
  module Core
    module Models
      
      # This class handles block options passed to the page size
      # method.
      #
      class PageSizeModel < BaseModel
        
        #-------------------------------------------------------------
        # Configuration
        #-------------------------------------------------------------
        
        # constants
        const_set(:DEFAULT_PAGE_WIDTH,  12240)  # 8.5in  in twips
        const_set(:DEFAULT_PAGE_HEIGHT, 15840)  # 11.0in in twips
        
        # accessors
        attr_reader :page_width
        attr_reader :page_height
        
        # initialization
        def initialize(options={}, &block)
          @page_width  = DEFAULT_PAGE_WIDTH
          @page_height = DEFAULT_PAGE_HEIGHT
          
          super options, &block
        end
        
        
        #-------------------------------------------------------------
        # Public Methods
        #-------------------------------------------------------------
    
        #=============== SETTERS ==============================
        
        def height(value)
          @page_height = value.to_i
        end
        
        def width(value)
          @page_width = value.to_i
        end
        
        
        #=============== VALIDATION ==============================
        
        def valid?
          dims = [page_width, page_height]
          dims.all? { |d| d > 0 }
        end
        
        
        #-------------------------------------------------------------
        # Private Instance Methods
        #-------------------------------------------------------------
        private
        
        def option_keys
          [:width, :height]
        end
        
      end
      
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
caracal-1.0.6 lib/caracal/core/models/page_size_model.rb
caracal-1.0.5 lib/caracal/core/models/page_size_model.rb
caracal-1.0.4 lib/caracal/core/models/page_size_model.rb
caracal-1.0.3 lib/caracal/core/models/page_size_model.rb
caracal-1.0.2 lib/caracal/core/models/page_size_model.rb
caracal-1.0.1 lib/caracal/core/models/page_size_model.rb
caracal-1.0.0 lib/caracal/core/models/page_size_model.rb
caracal-0.3.0 lib/caracal/core/models/page_size_model.rb
caracal-0.2.1 lib/caracal/core/models/page_size_model.rb
caracal-0.2.0 lib/caracal/core/models/page_size_model.rb
caracal-0.1.8 lib/caracal/core/models/page_size_model.rb
caracal-0.1.7 lib/caracal/core/models/page_size_model.rb
caracal-0.1.6 lib/caracal/core/models/page_size_model.rb
caracal-0.1.5 lib/caracal/core/models/page_size_model.rb
caracal-0.1.4 lib/caracal/core/models/page_size_model.rb
caracal-0.1.3 lib/caracal/core/models/page_size_model.rb
caracal-0.1.2 lib/caracal/core/models/page_size_model.rb