Class: ConfOption
- Inherits:
-
Object
- Object
- ConfOption
- Includes:
- BasicLogging, Translating
- Defined in:
- lib/gui/conf_option.rb
Overview
An object of this class represents a configuration-option.
It comprises the name, the value, the default-value, the data-type and the
documentation of such an option.
Defined Under Namespace
Classes: Error, InvalidOptionError, NoValueError
Constant Summary collapse
- @@Doc =
{ :pdf_prefix => Translating::trl( "The PDF-prefix and -suffix are added to the name of an eml-file to create the name of a resulting PDF-file, potentially keeping a numerical prefix intact, like in prefix_[num_]eml_suffix.pdf, e.g. mail_3_eml_arch.pdf."), :pdf_suffix => Translating::trl("The PDF-prefix and -suffix are added to the name of an eml-file to create the name of a resulting PDF-file, potentially keeping a numerical prefix intact, like in prefix_[num_]eml_suffix.pdf, e.g. mail_3_eml_arch.pdf."), :log_level => Translating::trl("The log-level can be fatal, error, warn, info or debug.") << ' ' << Translating::trl('Restart the program for changes to this option to take effect.'), :log_file => Translating::trl("Path to the protocol-file, where the logger-output will be directed, if configured. When left empty, stdout will be used."), :page_size => Translating::trl("Page size, e.g. A4"), :page_layout => Translating::trl("Page layout, one of portrait or landscape"), :regular_font => Translating::trl("Font-file to use in the PDF-file. By default, the fonts used in the PDF are those supported by the Ruby-gem \"Prawn\", i.e. Courier, Times-Roman and Helvetica or the respective replacement font, which is valid on your system. The font-file, that you name here, will replace Helvetica and be used for the headers and the body of the email in PDF-format. ATTN! For your font-settings to take effect, you must name ALL four font-files!"), :bold_font => Translating::trl("Font-file to use in the PDF-file. By default, the fonts used in the PDF are those supported by the Ruby-gem \"Prawn\", i.e. Courier, Times-Roman and Helvetica or the respective replacement font, which is valid on your system. The font-file, that you name here, will replace Helvetica and be used for the headers and the body of the email in PDF-format. ATTN! For your font-settings to take effect, you must name ALL four font-files!"), :italic_font => Translating::trl("Font-file to use in the PDF-file. By default, the fonts used in the PDF are those supported by the Ruby-gem \"Prawn\", i.e. Courier, Times-Roman and Helvetica or the respective replacement font, which is valid on your system. The font-file, that you name here, will replace Helvetica and be used for the headers and the body of the email in PDF-format. ATTN! For your font-settings to take effect, you must name ALL four font-files!"), :bold_italic_font => Translating::trl("Font-file to use in the PDF-file. By default, the fonts used in the PDF are those supported by the Ruby-gem \"Prawn\", i.e. Courier, Times-Roman and Helvetica or the respective replacement font, which is valid on your system. The font-file, that you name here, will replace Helvetica and be used for the headers and the body of the email in PDF-format. ATTN! For your font-settings to take effect, you must name ALL four font-files!"), :visible_headers => Translating::trl("The visible headers will be shown in the final pdf. Headers which are noted here *and* also under hidden headers, will anyway be honored (*not* ignored)."), :hidden_headers => Translating::trl("The hidden headers will be suppressed... they are still here for reference. Add more, as you stumble over new headers in your e-mail. Headers which are noted here *and* also under visible headers will anyway be honored (*not* ignored)."), :show_content_type => Translating::trl("This option controls wether a visible body-part is preceded by a line indicating the content-type, like \"text/plain; charset=ISO-8859-1; format=flowed\""), :content_type_color => Translating::trl("The color of the content-type"), :replacement_color => Translating::trl("This is the color of a replacement-character, where a character cannot be converted to UTF-8."), :replacement_char => Translating::trl("Symbols which will replace any character which cannot be converted to UTF-8."), :link_color => Translating::trl("Color for hyper-links"), :author => Translating::trl("Provided the pdftk-tool is installed and can be found in the environment path, the value of these variables will set the respective field in the meta-data of the resulting PDF-files. Leave empty to ignore..."), :subject => Translating::trl("Provided the pdftk-tool is installed and can be found in the environment path, the value of these variables will set the respective field in the meta-data of the resulting PDF-files. Leave empty to ignore... Default subject is the subject-line of the original mail."), :keywords => Translating::trl("Provided the pdftk-tool is installed and can be found in the environment path, the value of these variables will set the respective field in the meta-data of the resulting PDF-files. Leave empty to ignore..."), :title => Translating::trl("Provided the pdftk-tool is installed and can be found in the environment path, the value of these variables will set the respective field in the meta-data of the resulting PDF-files. Leave empty to ignore..."), :save_attachments => Translating::trl("If and where attachments shall be placed. Either 'pdf' to store files in the PDF (needs pdftk) or a directory path to store files in the given directory. A link to the file shall be provided in the PDF. The directory MUST EXIST, or 'false' to ignore the attachments"), :attachment_link_color => Translating::trl("The color of the links to saved attachments, if \"save attachments\" is set to a file path, rather than 'pdf'"), :pdf_reader => Translating::trl("A reader-application which can be used in different contexts to show a PDF-file."), }
- @@Default =
{ :pdf_prefix => '', :pdf_suffix => '', :log_level => 'unknown', :log_file => STDOUT, :page_size => 'A4', :page_layout => 'portrait', :regular_font => '', :bold_font => '', :italic_font => '', :bold_italic_font => '', :visible_headers => 'All mail-headers', :hidden_headers => '', :show_content_type => false, :content_type_color => '000080', :replacement_color => 'f08080', :replacement_char => '<?>', :link_color => '700000', :author => '', :subject => 'mail-subject', :keywords => '', :title => '', :save_attachments => 'pdf', :attachment_link_color => '008000', :pdf_reader => '' }
- @@Types =
{ :pdf_prefix => :string, :pdf_suffix => :string, :log_level => :choose_text, :log_file => :file, :page_size => :choose_text, :page_layout => :choose_text, :regular_font => :font, :bold_font => :font, :italic_font => :font, :bold_italic_font => :font, :visible_headers => :stringlist, :hidden_headers => :stringlist, :show_content_type => :bool, :content_type_color => :hexcolor, :replacement_color => :hexcolor, :replacement_char => :string, :link_color => :hexcolor, :author => :string, :subject => :string, :keywords => :string, :title => :string, :save_attachments => :choose_text, :attachment_link_color => :hexcolor, :pdf_reader => :file }
- @@Choices =
@@Pane_content = {
:show_content_type => :bool, :regular_font => :file, :bold_font => :file, :italic_font => :file, :bold_italic_font => :file, :attachment_link_color => :hexcolor, :visible_headers => :stringlist, :hidden_headers => :stringlist, :save_attachments => :choose_text, :content_type_color => :hexcolor, :replacement_color => :hexcolor, :replacement_char => :string, :link_color => :hexcolor, } @@Pane_pdf = { :pdf_prefix => :string, :pdf_suffix => :string, :page_size => :choose_text, :page_layout => :choose_text, :author => :string, :subject => :string, :keywords => :string, :title => :string, } @@Pane_program = { :log_level => :choose_text, :log_file => :file, :pdf_reader => :file }
{ :log_level => [:unknown, :debug, :info, :error, :fatal, :warn], :page_size => %w"4A0 2A0 A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 C10 RA0 RA1 RA2 RA3 RA4 SRA0 SRA1 SRA3 SRA4 EXECUTIVE FOLIO LEGAL LETTER".collect{|ps| ps.to_sym}, :page_layout => [:portrait, :landscape], :save_attachments => [:pdf, :path, :false] }
- @@Constraints =
{ :pdf_reader => [:exist, :file, :executable], :save_attachments => [:exist, :directory, :writable], :bold_font => [:exist, :file, :readable], :italic_font => [:exist, :file, :readable], :bold_italic_font => [:exist, :file, :readable], :regular_font => [:exist, :file, :readable], }
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Instance Attribute Summary collapse
-
#choices ⇒ Object
readonly
Returns the value of attribute choices.
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#display_name ⇒ Object
readonly
Returns the value of attribute display_name.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes included from BasicLogging
Instance Method Summary collapse
- #display_value ⇒ Object
- #doc ⇒ Object
-
#initialize(name, value = nil) ⇒ ConfOption
constructor
A new instance of ConfOption.
- #to_s ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
Methods included from BasicLogging
is_muted?, #log, mute, #set_level, #set_target
Methods included from Translating
Constructor Details
#initialize(name, value = nil) ⇒ ConfOption
Returns a new instance of ConfOption.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/gui/conf_option.rb', line 192 def initialize(name, value = nil) keys = @@Types.keys nkey = name.downcase.gsub(' ', '_').to_sym @name = name if(keys.include?(nkey)) debug("configuring " << nkey.to_s << ", value is " << value.to_s) @display_name = trl(name) @otype = @@Types[nkey] debug('set otype ' << @otype.to_s) @choices = @@Choices[nkey] if @@Choices.keys.include?(nkey) @doc = @@Doc[nkey] @default = @@Default[nkey] @constraints = @@Constraints[nkey] begin if(!@constraints && @choices && !@choices.include?(value ? value.to_sym : ''.to_sym) ) = trl("Value %s is not permitted for option %s!") %[(value && !value.empty? ? trl(value.to_s) : '(empty)') , name] << "\nSetting default-value %s" %(@default.to_s ) warn() msg_dialog(, 'warning' ) @value = ConfValue.new(@name, @default) else @value = ConfValue.new(@name, value) end rescue Exception => ex error('Error in configuration-option ' << @name << ': ' << ex.) end else @doc = 'N I L' @default = 'N I L' msg = trl("Unknown configuration-option %s!") %name error(msg) raise InvalidOptionError, "An option \"" << name << "\" does not exist!" ; end debug "Option #{name} is initialized" end |
Instance Attribute Details
#choices ⇒ Object (readonly)
Returns the value of attribute choices.
232 233 234 |
# File 'lib/gui/conf_option.rb', line 232 def choices @choices end |
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
232 233 234 |
# File 'lib/gui/conf_option.rb', line 232 def constraints @constraints end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
232 233 234 |
# File 'lib/gui/conf_option.rb', line 232 def default @default end |
#display_name ⇒ Object (readonly)
Returns the value of attribute display_name.
232 233 234 |
# File 'lib/gui/conf_option.rb', line 232 def display_name @display_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
232 233 234 |
# File 'lib/gui/conf_option.rb', line 232 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
232 233 234 |
# File 'lib/gui/conf_option.rb', line 232 def type @type end |
Instance Method Details
#display_value ⇒ Object
262 263 264 |
# File 'lib/gui/conf_option.rb', line 262 def display_value @value.display_value end |
#doc ⇒ Object
266 267 268 269 270 271 272 |
# File 'lib/gui/conf_option.rb', line 266 def doc if !@doc error(trl("Option %s is missing a documentation.") %(@name) ) else @doc end end |
#to_s ⇒ Object
234 235 236 |
# File 'lib/gui/conf_option.rb', line 234 def to_s self.class.name.dup << ': name = ' << @name << ', value = ' << (@value ? @value.to_s : 'N I L') << ', default = ' << @default.to_s << ', doc = ' << @doc end |
#value ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/gui/conf_option.rb', line 246 def value if (@otype != :bool && !@value) msg = trl("No value has been set for option %s.") %(@name) warn(msg) nil elsif @value @value.value else nil end end |