Class: Indoctrinatr::Tools::FieldNameValues
- Inherits:
-
ContentForTexFiles
- Object
- ContentForTexFiles
- Indoctrinatr::Tools::FieldNameValues
- Defined in:
- lib/indoctrinatr/tools/field_name_values.rb
Overview
This class defines the content for a document that has the field names as content.
Constant Summary collapse
- PICTURE_FILE_ENDINGS =
%w[.png .jpeg .jpg .bmp .gif .pdf].freeze
Instance Method Summary collapse
-
#_field_names_as_values ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#detect_picture_file_names(string_to_check) ⇒ Object
Indoctrinatr has no picture data type.
-
#overwrite_picture_file_names_output(attributes_as_hashes) ⇒ Object
The LaTeX compilation would fail if the includegraphics tries to include a file that does not exist.
Methods inherited from ContentForTexFiles
#_build_from_configuration, #customized_output_file_name, #initialize, #retrieve_binding, #template_asset_path, #textile2latex
Constructor Details
This class inherits a constructor from Indoctrinatr::Tools::ContentForTexFiles
Instance Method Details
#_field_names_as_values ⇒ Object
rubocop:disable Metrics/AbcSize
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/indoctrinatr/tools/field_name_values.rb', line 7 def _field_names_as_values # rubocop:disable Metrics/AbcSize @_configuration.attributes_as_hashes_in_array.each do |attribute_hash| # Usage of \textless to avoid issues with the < > characters. # Usage of * character because it does not produce any issues when it's used in arguments of LaTeX commands. # Initially the intention was to use texttt, but that had this problem. instance_variable_set("@_#{attribute_hash['name']}", "\\textless***#{attribute_hash['name'].to_latex}***\\textgreater") define_singleton_method "raw_#{attribute_hash['name']}".to_sym do "raw\\_#{instance_variable_get("@_#{attribute_hash['name']}")}" end define_singleton_method attribute_hash['name'].to_sym do # No usage of to_latex because we escaped variable name already and want no escaping for the other stuff instance_variable_get("@_#{attribute_hash['name']}") end end # This overwrites the instance attributes and methods again overwrite_picture_file_names_output @_configuration.attributes_as_hashes_in_array end |
#detect_picture_file_names(string_to_check) ⇒ Object
Indoctrinatr has no picture data type. This means that the only way to check for pictures is to check for file endings. If an user has obscure file type the possibility list would have to get updated.
49 50 51 52 53 |
# File 'lib/indoctrinatr/tools/field_name_values.rb', line 49 def detect_picture_file_names(string_to_check) PICTURE_FILE_ENDINGS.any? do |picture_file_ending| string_to_check.downcase.include? picture_file_ending # http://stackoverflow.com/a/3686568 end end |
#overwrite_picture_file_names_output(attributes_as_hashes) ⇒ Object
The LaTeX compilation would fail if the includegraphics tries to include a file that does not exist. Because of that it makes sense to simply use the default values again if user sets file names.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/indoctrinatr/tools/field_name_values.rb', line 30 def overwrite_picture_file_names_output(attributes_as_hashes) # rubocop:disable Metrics/AbcSize attributes_as_hashes.each do |attribute_hash| # search for typical picture file endings next unless detect_picture_file_names attribute_hash['default_value'] instance_variable_set("@_#{attribute_hash['name']}", attribute_hash['default_value']) define_singleton_method "raw_#{attribute_hash['name']}".to_sym do "raw\\_#{instance_variable_get("@_#{attribute_hash['name']}")}" end define_singleton_method attribute_hash['name'].to_sym do instance_variable_get("@_#{attribute_hash['name']}").to_latex end end end |