Class: Pdfh::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfh/models/settings.rb

Overview

Handles the config yaml data mapping, and associates a file name with a doc type. This is a pure data object — validation is handled by Services::SettingsValidator.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lookup_dirs:, base_path:, document_types:) ⇒ Settings

Parameters:

  • lookup_dirs (Array<String>)

    Already validated and expanded directories

  • base_path (String)

    Already validated and expanded base path

  • document_types (Hash{String => DocumentType})

    Already validated document types keyed by gid



17
18
19
20
21
# File 'lib/pdfh/models/settings.rb', line 17

def initialize(lookup_dirs:, base_path:, document_types:)
  @lookup_dirs = lookup_dirs
  @base_path = base_path
  @document_types = document_types
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



11
# File 'lib/pdfh/models/settings.rb', line 11

attr_reader :lookup_dirs, :base_path

#lookup_dirsArray<String> (readonly)

Returns List of validated, expanded directories to look up for processing.

Returns:

  • (Array<String>)

    List of validated, expanded directories to look up for processing.



11
12
13
# File 'lib/pdfh/models/settings.rb', line 11

def lookup_dirs
  @lookup_dirs
end

Instance Method Details

#document_type(id) ⇒ DocumentType

Returns:



37
38
39
# File 'lib/pdfh/models/settings.rb', line 37

def document_type(id)
  @document_types[id]
end

#document_typesArray<DocumentType>

Returns:



24
# File 'lib/pdfh/models/settings.rb', line 24

def document_types = @document_types.values

#document_types_name_max_sizeInteger

Examples:

# document_types.map(&:name) ['12345', '12', '123']
settings.document_types_name_max_size #=> 5

Returns:

  • (Integer)


30
31
32
33
34
# File 'lib/pdfh/models/settings.rb', line 30

def document_types_name_max_size
  return 0 if document_types.empty?

  document_types.map { _1.name.length }.max
end