Class: TnPDF::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/tn_pdf/configuration.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.image_loaderObject

Returns the value of attribute image_loader.



7
8
9
# File 'lib/tn_pdf/configuration.rb', line 7

def image_loader
  @image_loader
end

Class Method Details

.[](property, call_procs: true) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/tn_pdf/configuration.rb', line 9

def [](property, call_procs: true)
  (hash, key) = filter_property(property)
  value = hash[key]

  if call_procs && value.kind_of?(Proc)
    value.call
  else
    value
  end
end

.[]=(property, value) ⇒ Object



20
21
22
23
24
25
# File 'lib/tn_pdf/configuration.rb', line 20

def []=(property, value)
  (hash, key) = filter_property(property)
  value = perform_conversions(value)

  hash[key] = value
end


35
36
37
# File 'lib/tn_pdf/configuration.rb', line 35

def footer_properties_names
  footer.keys
end

.header_properties_namesObject



31
32
33
# File 'lib/tn_pdf/configuration.rb', line 31

def header_properties_names
  header.keys
end

.load_from(yaml_file) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/tn_pdf/configuration.rb', line 50

def load_from(yaml_file)
  configurations = YAML.load_file(yaml_file)

  configurations.each do |item, value|
    value = perform_conversions(value)
    self.send(item).merge! value
  end
end

.perform_conversions(value) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/tn_pdf/configuration.rb', line 59

def perform_conversions(value)
  match = value.match(/^(\d+\.?\d*)(cm|mm)$/) rescue nil
  if match
    num = match[1].to_f
    conversion = match[2].to_sym
    num.send(conversion)
  elsif value.kind_of? Hash
    value.inject({}) do |hash, (k, v)|
      hash[k.to_sym] = perform_conversions(v)
      hash
    end
  elsif value.kind_of? Array
    value.inject([]) do |array, v|
      array << perform_conversions(v)
      array
    end
  else
    value
  end
end

.properties_namesObject



43
44
45
46
47
48
# File 'lib/tn_pdf/configuration.rb', line 43

def properties_names
  report_properties_names.map { |p| "report_#{p}" }  +
    header_properties_names.map { |p| "page_header_#{p}" } +
    footer_properties_names.map { |p| "page_footer_#{p}" } +
    table_properties_names.map { |p| "table_#{p}" }
end

.report_properties_namesObject



27
28
29
# File 'lib/tn_pdf/configuration.rb', line 27

def report_properties_names
  report.keys
end

.table_properties_namesObject



39
40
41
# File 'lib/tn_pdf/configuration.rb', line 39

def table_properties_names
  table.keys
end