Sha256: de2da045fab323d6fe0a7430991090af6460e041f98e3a17f1f60b001f7e845e

Contents?: true

Size: 1.81 KB

Versions: 1

Compression:

Stored size: 1.81 KB

Contents

require 'caracal/core/models/base_model'


module Caracal
  module Core
    module Models
      
      # This class handles block options passed to the page_numbers
      # method.
      #
      class PageNumberModel < BaseModel
        
        #-------------------------------------------------------------
        # Configuration
        #-------------------------------------------------------------
        
        # constants
        const_set(:DEFAULT_PAGE_NUMBER_SHOW,  false)
        const_set(:DEFAULT_PAGE_NUMBER_ALIGN, :center)
        
        # accessors
        attr_reader :page_number_align
        attr_reader :page_number_show
        
        # initialization
        def initialize(**options, &block)
          @page_number_show  = DEFAULT_PAGE_NUMBER_SHOW
          @page_number_align = DEFAULT_PAGE_NUMBER_ALIGN
          
          super options, &block
        end
        
        
        #-------------------------------------------------------------
        # Public Methods
        #-------------------------------------------------------------
    
        #=============== SETTERS ==============================
        
        def align(value)
          @page_number_align = value.to_s.to_sym
        end
        
        def show(value)
          @page_number_show = !!value
        end
        
        
        #=============== VALIDATION ===========================
        
        def valid?
          (!page_number_show || [:left, :center, :right].include?(page_number_align))
        end
        
        
        #-------------------------------------------------------------
        # Private Instance Methods
        #-------------------------------------------------------------
        private
        
        def option_keys
          [:align, :show]
        end
        
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caracal-0.1.0 lib/caracal/core/models/page_number_model.rb