Class: Pdfh::DocumentType
- Inherits:
-
Object
- Object
- Pdfh::DocumentType
- Includes:
- Concerns::PasswordDecodable
- Defined in:
- lib/pdfh/models/document_type.rb
Overview
Represents a type of document that can be processed by pdfh
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the document type.
-
#name_template ⇒ String
readonly
The template for generating document names.
-
#pwd ⇒ String?
readonly
The base64 password for the document type, if any.
-
#re_date ⇒ Regexp
readonly
The regular expression to extract dates and its information.
-
#re_file ⇒ Regexp
readonly
The regular expression to match file names.
-
#store_path ⇒ String
readonly
The path where the document will be stored.
-
#sub_types ⇒ Object
readonly
Returns the value of attribute sub_types.
Instance Method Summary collapse
- #generate_new_name(values) ⇒ String
- #generate_path(values) ⇒ String
-
#gid ⇒ String
removes special characters from string and replaces spaces with dashes.
- #initialize(args) ⇒ self constructor
-
#sub_type(text) ⇒ DocumentSubType
search the subtype name in the pdf document.
-
#to_h ⇒ Hash{Symbol->any
].
Methods included from Concerns::PasswordDecodable
Constructor Details
#initialize(args) ⇒ self
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pdfh/models/document_type.rb', line 26 def initialize(args) args.each { |k, v| instance_variable_set(:"@#{k}", v) } @name_template ||= "{original}" @re_file = Regexp.new(re_file) @re_date = Regexp.new(re_date) @sub_types = extract_subtypes(sub_types) if sub_types&.any? @path_validator = RenameValidator.new(store_path) @name_validator = RenameValidator.new(name_template) return if @path_validator.valid? && @name_validator.valid? raise_validators_error end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns The name of the document type.
22 23 24 |
# File 'lib/pdfh/models/document_type.rb', line 22 def name @name end |
#name_template ⇒ String (readonly)
Returns The template for generating document names.
22 |
# File 'lib/pdfh/models/document_type.rb', line 22 attr_reader :name, :re_file, :re_date, :pwd, :store_path, :name_template, :sub_types |
#pwd ⇒ String? (readonly)
Returns The base64 password for the document type, if any.
22 |
# File 'lib/pdfh/models/document_type.rb', line 22 attr_reader :name, :re_file, :re_date, :pwd, :store_path, :name_template, :sub_types |
#re_date ⇒ Regexp (readonly)
Returns The regular expression to extract dates and its information.
22 |
# File 'lib/pdfh/models/document_type.rb', line 22 attr_reader :name, :re_file, :re_date, :pwd, :store_path, :name_template, :sub_types |
#re_file ⇒ Regexp (readonly)
Returns The regular expression to match file names.
22 |
# File 'lib/pdfh/models/document_type.rb', line 22 attr_reader :name, :re_file, :re_date, :pwd, :store_path, :name_template, :sub_types |
#store_path ⇒ String (readonly)
Returns The path where the document will be stored.
22 |
# File 'lib/pdfh/models/document_type.rb', line 22 attr_reader :name, :re_file, :re_date, :pwd, :store_path, :name_template, :sub_types |
#sub_types ⇒ Object (readonly)
Returns the value of attribute sub_types.
22 |
# File 'lib/pdfh/models/document_type.rb', line 22 attr_reader :name, :re_file, :re_date, :pwd, :store_path, :name_template, :sub_types |
Instance Method Details
#generate_new_name(values) ⇒ String
62 63 64 |
# File 'lib/pdfh/models/document_type.rb', line 62 def generate_new_name(values) @name_validator.gsub(values) end |
#generate_path(values) ⇒ String
68 69 70 |
# File 'lib/pdfh/models/document_type.rb', line 68 def generate_path(values) @path_validator.gsub(values) end |
#gid ⇒ String
removes special characters from string and replaces spaces with dashes
49 50 51 |
# File 'lib/pdfh/models/document_type.rb', line 49 def gid name.downcase.gsub(/[^0-9A-Za-z\s]/, "").tr(" ", "-") end |
#sub_type(text) ⇒ DocumentSubType
search the subtype name in the pdf document
55 56 57 58 |
# File 'lib/pdfh/models/document_type.rb', line 55 def sub_type(text) # Regexp.new(st.name).match?(name) sub_types&.find { |st| /#{st.name}/i.match?(text) } end |
#to_h ⇒ Hash{Symbol->any
Returns ].
40 41 42 |
# File 'lib/pdfh/models/document_type.rb', line 40 def to_h instance_variables.to_h { |var| [var.to_s.delete_prefix("@"), instance_variable_get(var)] } end |