Class: Pdfh::RenameValidator
- Inherits:
-
Object
- Object
- Pdfh::RenameValidator
- Defined in:
- lib/pdfh/utils/rename_validator.rb
Overview
Validates the rename template, and generate new name
Constant Summary collapse
- RENAME_TYPES =
{ "original" => "No name change", "period" => "Year-Month", "year" => "Year", "month" => "Month", "type" => "Document Type name", "subtype" => "Document Subtype name", "extra" => "Extra data extracted from date_re" }.freeze
Instance Attribute Summary collapse
-
#all ⇒ Object
readonly
Returns the value of attribute all.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#unknown ⇒ Object
readonly
Returns the value of attribute unknown.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
Instance Method Summary collapse
- #gsub(values) ⇒ String (frozen)
- #initialize(template) ⇒ self constructor
- #types ⇒ Array<String>
- #unknown_list ⇒ String
- #valid? ⇒ Boolean
Constructor Details
#initialize(template) ⇒ self
20 21 22 23 24 25 |
# File 'lib/pdfh/utils/rename_validator.rb', line 20 def initialize(template) @template = template @all = template.scan(/{([^}]+)}/).flatten.map(&:downcase) @unknown = all - types @valid = all - unknown end |
Instance Attribute Details
#all ⇒ Object (readonly)
Returns the value of attribute all.
16 17 18 |
# File 'lib/pdfh/utils/rename_validator.rb', line 16 def all @all end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
16 17 18 |
# File 'lib/pdfh/utils/rename_validator.rb', line 16 def template @template end |
#unknown ⇒ Object (readonly)
Returns the value of attribute unknown.
16 17 18 |
# File 'lib/pdfh/utils/rename_validator.rb', line 16 def unknown @unknown end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
16 17 18 |
# File 'lib/pdfh/utils/rename_validator.rb', line 16 def valid @valid end |
Instance Method Details
#gsub(values) ⇒ String (frozen)
44 45 46 47 48 |
# File 'lib/pdfh/utils/rename_validator.rb', line 44 def gsub(values) template .gsub(/\{([^}]+)}/, &:downcase) # convert all text between {} to lowercase .gsub("{", "%{") % values end |
#types ⇒ Array<String>
28 29 30 |
# File 'lib/pdfh/utils/rename_validator.rb', line 28 def types RENAME_TYPES.keys end |
#unknown_list ⇒ String
38 39 40 |
# File 'lib/pdfh/utils/rename_validator.rb', line 38 def unknown_list unknown.join(", ") end |
#valid? ⇒ Boolean
33 34 35 |
# File 'lib/pdfh/utils/rename_validator.rb', line 33 def valid? unknown.empty? end |