Class: Condom::Base
- Inherits:
-
Object
- Object
- Condom::Base
- 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
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#date ⇒ Object
Returns the value of attribute date.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#document_class ⇒ Object
Returns the value of attribute document_class.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#language ⇒ Object
Returns the value of attribute language.
-
#other_packages ⇒ Object
Returns the value of attribute other_packages.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#create ⇒ Object
This method will create in output directory all needed files.
-
#get_options ⇒ Object
This method returns a hash of the options of the document.
-
#initialize(args = nil) ⇒ Base
constructor
The constructor.
-
#set_options(hash) ⇒ Object
This method sets options of the document given in a hash.
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 ({ :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 args end end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
10 11 12 |
# File 'lib/condom/base.rb', line 10 def @author end |
#date ⇒ Object
Returns the value of attribute date.
10 11 12 |
# File 'lib/condom/base.rb', line 10 def date @date end |
#directory ⇒ Object
Returns the value of attribute directory.
10 11 12 |
# File 'lib/condom/base.rb', line 10 def directory @directory end |
#document_class ⇒ Object
Returns the value of attribute document_class.
10 11 12 |
# File 'lib/condom/base.rb', line 10 def document_class @document_class end |
#filename ⇒ Object
Returns the value of attribute filename.
10 11 12 |
# File 'lib/condom/base.rb', line 10 def filename @filename end |
#language ⇒ Object
Returns the value of attribute language.
10 11 12 |
# File 'lib/condom/base.rb', line 10 def language @language end |
#other_packages ⇒ Object
Returns the value of attribute other_packages.
10 11 12 |
# File 'lib/condom/base.rb', line 10 def other_packages @other_packages end |
#title ⇒ Object
Returns the value of attribute title.
10 11 12 |
# File 'lib/condom/base.rb', line 10 def title @title end |
Instance Method Details
#create ⇒ Object
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_options ⇒ Object
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 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 (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 |