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", "quarter" => "Quarter (Q1-Q4)", "bimester" => "Bimester (B1-B6)", "name" => "Document Type name", "day" => "Day of month" }.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
21 22 23 24 25 26 |
# File 'lib/pdfh/utils/rename_validator.rb', line 21 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.
17 18 19 |
# File 'lib/pdfh/utils/rename_validator.rb', line 17 def all @all end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
17 18 19 |
# File 'lib/pdfh/utils/rename_validator.rb', line 17 def template @template end |
#unknown ⇒ Object (readonly)
Returns the value of attribute unknown.
17 18 19 |
# File 'lib/pdfh/utils/rename_validator.rb', line 17 def unknown @unknown end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
17 18 19 |
# File 'lib/pdfh/utils/rename_validator.rb', line 17 def valid @valid end |
Instance Method Details
#gsub(values) ⇒ String (frozen)
45 46 47 48 49 |
# File 'lib/pdfh/utils/rename_validator.rb', line 45 def gsub(values) template .gsub(/\{([^}]+)}/, &:downcase) # convert all text between {} to lowercase .gsub("{", "%{") % values end |
#types ⇒ Array<String>
29 30 31 |
# File 'lib/pdfh/utils/rename_validator.rb', line 29 def types RENAME_TYPES.keys end |
#unknown_list ⇒ String
39 40 41 |
# File 'lib/pdfh/utils/rename_validator.rb', line 39 def unknown_list unknown.join(", ") end |
#valid? ⇒ Boolean
34 35 36 |
# File 'lib/pdfh/utils/rename_validator.rb', line 34 def valid? unknown.empty? end |