Module: Caracal::Core::FileName

Included in:
Document
Defined in:
lib/caracal/core/file_name.rb

Overview

This module encapsulates all the functionality related to setting the document’s name.

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/caracal/core/file_name.rb', line 8

def self.included(base)
  base.class_eval do

    #-------------------------------------------------------------
    # Configuration
    #-------------------------------------------------------------

    # constants
    const_set(:DEFAULT_FILE_NAME, 'caracal.docx')

    # accessors
    attr_reader :name
    attr_reader :path


    #-------------------------------------------------------------
    # Public Methods
    #-------------------------------------------------------------

    # This method sets the name of the output file. Defaults
    # to the name of the library.
    #
    def file_name(value=nil)
      v = value.to_s.strip
      a = v.split('/')

      @name = (v == '') ? self.class::DEFAULT_FILE_NAME : a.last
      @path = (a.size > 1) ? v : "./#{ v }"
    end

  end
end