Class: Condom::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/condom/base.rb

Overview

The Base class. This is the main class of the condom lib. It will contain all common attributes and methods to every LaTeX document.

Direct Known Subclasses

CV, Classic, Letter, Presentation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Base

The constructor. args could be:

  • nothing,

  • the title of the document,

  • a hash of options.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/condom/base.rb', line 19

def initialize(args = nil)
  # Need to initialize each variables else they won't exist in instance_variables.
  @directory = @filename = @author = @title = @date = @document_class = @language = @other_packages = nil

  # The default options
  set_options({
    :directory      => Dir.getwd,
    :filename       => 'main',
    :author         => Condom.get_user_name,
    :title          => 'Document \LaTeX',
    :date           => '\today',
    :document_class => 'article',
    :language       => 'francais',
    :other_packages => Array.new
  })

  if args.is_a? String
    @title = args
  elsif args.is_a? Hash
    set_options args
  end
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



10
11
12
# File 'lib/condom/base.rb', line 10

def author
  @author
end

#dateObject

Returns the value of attribute date.



10
11
12
# File 'lib/condom/base.rb', line 10

def date
  @date
end

#directoryObject

Returns the value of attribute directory.



10
11
12
# File 'lib/condom/base.rb', line 10

def directory
  @directory
end

#document_classObject

Returns the value of attribute document_class.



10
11
12
# File 'lib/condom/base.rb', line 10

def document_class
  @document_class
end

#filenameObject

Returns the value of attribute filename.



10
11
12
# File 'lib/condom/base.rb', line 10

def filename
  @filename
end

#languageObject

Returns the value of attribute language.



10
11
12
# File 'lib/condom/base.rb', line 10

def language
  @language
end

#other_packagesObject

Returns the value of attribute other_packages.



10
11
12
# File 'lib/condom/base.rb', line 10

def other_packages
  @other_packages
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/condom/base.rb', line 10

def title
  @title
end

Instance Method Details

#createObject

This method will create in output directory all needed files.



65
66
67
68
69
# File 'lib/condom/base.rb', line 65

def create
  in_directory do
    raise("Please use a specific Condom class, not Base.")
  end
end

#get_optionsObject

This method returns a hash of the options of the document.



43
44
45
46
47
48
49
50
# File 'lib/condom/base.rb', line 43

def get_options
  hash = Hash.new
  instance_variables.each do |var|
    hash[var[1..-1].to_sym] = instance_variable_get(var)
  end

  return hash
end

#set_options(hash) ⇒ Object

This method sets options of the document given in a hash



53
54
55
56
57
58
59
60
61
62
# File 'lib/condom/base.rb', line 53

def set_options(hash)
  hash.keys.each do |key|
    var = '@' << key.to_s
    # = 1.9.* Fix
    # The map method applied on instance_variables is used to force elements to be String
    # because on 1.9.* Ruby versions, these elements are Symbol (i.e. :@directory).
    raise("Key #{key} not supported.") unless instance_variables.map {|v| v.to_s}.include? var
    instance_variable_set(var, hash[key])
  end
end