Class: Pdfh::DocumentType

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

Overview

Represents a type of document that can be processed by pdfh

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ self



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pdfh/models/document_type.rb', line 8

def initialize(args)
  super
  self.name_template ||= "{original}"
  self.re_file = Regexp.new(re_file)
  self.re_date = Regexp.new(re_date)
  self.sub_types = extract_subtype(sub_types) if sub_types
  @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

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



5
6
7
# File 'lib/pdfh/models/document_type.rb', line 5

def name
  @name
end

#name_templateObject

Returns the value of attribute name_template

Returns:

  • (Object)

    the current value of name_template



5
6
7
# File 'lib/pdfh/models/document_type.rb', line 5

def name_template
  @name_template
end

Returns the value of attribute print_cmd

Returns:

  • (Object)

    the current value of print_cmd



5
6
7
# File 'lib/pdfh/models/document_type.rb', line 5

def print_cmd
  @print_cmd
end

#pwdObject

Returns the value of attribute pwd

Returns:

  • (Object)

    the current value of pwd



5
6
7
# File 'lib/pdfh/models/document_type.rb', line 5

def pwd
  @pwd
end

#re_dateObject

Returns the value of attribute re_date

Returns:

  • (Object)

    the current value of re_date



5
6
7
# File 'lib/pdfh/models/document_type.rb', line 5

def re_date
  @re_date
end

#re_fileObject

Returns the value of attribute re_file

Returns:

  • (Object)

    the current value of re_file



5
6
7
# File 'lib/pdfh/models/document_type.rb', line 5

def re_file
  @re_file
end

#store_pathObject

Returns the value of attribute store_path

Returns:

  • (Object)

    the current value of store_path



5
6
7
# File 'lib/pdfh/models/document_type.rb', line 5

def store_path
  @store_path
end

#sub_typesObject

Returns the value of attribute sub_types

Returns:

  • (Object)

    the current value of sub_types



5
6
7
# File 'lib/pdfh/models/document_type.rb', line 5

def sub_types
  @sub_types
end

Instance Method Details

#generate_new_name(values) ⇒ String

Parameters:

  • values (Hash{Symbol->String)

Returns:



45
46
47
# File 'lib/pdfh/models/document_type.rb', line 45

def generate_new_name(values)
  @name_validator.gsub(values)
end

#generate_path(values) ⇒ String

Parameters:

  • values (Hash{Symbol->String)

Returns:



51
52
53
# File 'lib/pdfh/models/document_type.rb', line 51

def generate_path(values)
  @path_validator.gsub(values)
end

#gidString

removes special characters from string and replaces spaces with dashes

Examples:

usage

"Test This?%&".gid
# => "test-this"

Returns:



26
27
28
# File 'lib/pdfh/models/document_type.rb', line 26

def gid
  name.downcase.gsub(/[^0-9A-Za-z\s]/, "").tr(" ", "-")
end

#passwordString

Returns:



37
38
39
40
41
# File 'lib/pdfh/models/document_type.rb', line 37

def password
  return Base64.decode64(pwd) if base64?

  pwd
end

#sub_type(text) ⇒ DocumentSubType

Returns:



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

def sub_type(text)
  # Regexp.new(st.name).match?(name)
  sub_types&.find { |st| /#{st.name}/i.match?(text) }
end