Class: Pdfh::Document
- Inherits:
-
Object
- Object
- Pdfh::Document
- Defined in:
- lib/pdfh/models/document.rb
Overview
Handles the PDF detected by the rules
Instance Attribute Summary collapse
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #backup_name ⇒ String
- #companion_files(join: false) ⇒ String (frozen)
- #file_extension ⇒ String
- #file_name ⇒ String
- #file_name_only ⇒ String
- #home_dir ⇒ String
- #initialize(file, type, text) ⇒ self constructor
- #new_name ⇒ String
- #print_info ⇒ void
- #print_info_line(property, info) ⇒ void
- #process ⇒ void
-
#rename_data ⇒ Hash{Symbol->String
].
- #store_path ⇒ String
- #sub_type ⇒ String
- #to_s ⇒ String
- #type_name ⇒ String
Constructor Details
#initialize(file, type, text) ⇒ self
12 13 14 15 16 |
# File 'lib/pdfh/models/document.rb', line 12 def initialize(file, type, text) @file = file @type = type @text = text end |
Instance Attribute Details
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
6 7 8 |
# File 'lib/pdfh/models/document.rb', line 6 def extra @extra end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/pdfh/models/document.rb', line 6 def file @file end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
6 7 8 |
# File 'lib/pdfh/models/document.rb', line 6 def period @period end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
6 7 8 |
# File 'lib/pdfh/models/document.rb', line 6 def text @text end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/pdfh/models/document.rb', line 6 def type @type end |
Instance Method Details
#backup_name ⇒ String
63 64 65 |
# File 'lib/pdfh/models/document.rb', line 63 def backup_name "#{file_name}.bkp" end |
#companion_files(join: false) ⇒ String (frozen)
102 103 104 105 106 |
# File 'lib/pdfh/models/document.rb', line 102 def companion_files(join: false) return @companion unless join @companion.empty? ? "N/A" : @companion.join(", ") end |
#file_extension ⇒ String
53 54 55 |
# File 'lib/pdfh/models/document.rb', line 53 def file_extension File.extname(@file) end |
#file_name ⇒ String
58 59 60 |
# File 'lib/pdfh/models/document.rb', line 58 def file_name File.basename(@file) end |
#file_name_only ⇒ String
48 49 50 |
# File 'lib/pdfh/models/document.rb', line 48 def file_name_only File.basename(@file, file_extension) end |
#home_dir ⇒ String
109 110 111 |
# File 'lib/pdfh/models/document.rb', line 109 def home_dir File.dirname(@file) end |
#new_name ⇒ String
91 92 93 94 |
# File 'lib/pdfh/models/document.rb', line 91 def new_name new_name = type.generate_new_name(rename_data) "#{new_name}#{file_extension}" end |
#print_info ⇒ void
This method returns an undefined value.
32 33 34 35 36 37 38 39 40 |
# File 'lib/pdfh/models/document.rb', line 32 def print_info print_info_line "Type", type.name print_info_line "Sub-Type", sub_type print_info_line "Period", period print_info_line "New Name", new_name print_info_line "Store Path", store_path print_info_line "Extra files", companion_files(join: true) print_info_line "Processed?", "No (in Dry mode)" if Pdfh.dry? end |
#print_info_line(property, info) ⇒ void
This method returns an undefined value.
43 44 45 |
# File 'lib/pdfh/models/document.rb', line 43 def print_info_line(property, info) Pdfh.ident_print property, info.to_s, color: :light_blue, width: 12 end |
#process ⇒ void
This method returns an undefined value.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pdfh/models/document.rb', line 19 def process Pdfh.debug "=== Document Type: #{type.name} ==============================" Pdfh.debug "~~~~~~~~~~~~~~~~~~ Finding a subtype" @sub_type = type.sub_type(@text) Pdfh.debug " SubType: #{@sub_type}" @companion = search_companion_files month, year, @extra = match_date(@sub_type&.re_date || @type.re_date) @period = DocumentPeriod.new(day: extra, month: month, month_offset: @sub_type&.month_offset, year: year) Pdfh.debug " Period: #{@period.inspect}" end |
#rename_data ⇒ Hash{Symbol->String
Returns ].
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/pdfh/models/document.rb', line 78 def rename_data { original: file_name_only, period: period.to_s, year: period.year.to_s, month: period.month.to_s, type: type_name, subtype: sub_type, extra: extra || "" }.freeze end |
#store_path ⇒ String
97 98 99 |
# File 'lib/pdfh/models/document.rb', line 97 def store_path type.generate_path(rename_data) end |
#sub_type ⇒ String
73 74 75 |
# File 'lib/pdfh/models/document.rb', line 73 def sub_type @sub_type&.name&.titleize || "N/A" end |
#type_name ⇒ String
68 69 70 |
# File 'lib/pdfh/models/document.rb', line 68 def type_name type&.name&.titleize || "N/A" end |