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_cmd ⇒ String
- #print_info ⇒ void
- #print_info_line(property, info) ⇒ 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 17 18 19 20 21 22 23 24 25 |
# File 'lib/pdfh/models/document.rb', line 12 def initialize(file, type, text) @file = file @type = type Pdfh.debug "=== Document Type: #{type.name} ==============================" @text = text Pdfh.debug "~~~~~~~~~~~~~~~~~~ Finding a subtype" @sub_type = type.sub_type(@text) Pdfh.debug " SubType: #{@sub_type}" @companion = search_companion_files month, year, @extra = match_data @period = DocumentPeriod.new(day: extra, month: month, month_offset: @sub_type&.month_offset, year: year) Pdfh.debug " Period: #{@period.inspect}" 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
60 61 62 |
# File 'lib/pdfh/models/document.rb', line 60 def backup_name "#{file_name}.bkp" end |
#companion_files(join: false) ⇒ String (frozen)
107 108 109 110 111 |
# File 'lib/pdfh/models/document.rb', line 107 def companion_files(join: false) return @companion unless join @companion.empty? ? "N/A" : @companion.join(", ") end |
#file_extension ⇒ String
50 51 52 |
# File 'lib/pdfh/models/document.rb', line 50 def file_extension File.extname(@file) end |
#file_name ⇒ String
55 56 57 |
# File 'lib/pdfh/models/document.rb', line 55 def file_name File.basename(@file) end |
#file_name_only ⇒ String
45 46 47 |
# File 'lib/pdfh/models/document.rb', line 45 def file_name_only File.basename(@file, file_extension) end |
#home_dir ⇒ String
114 115 116 |
# File 'lib/pdfh/models/document.rb', line 114 def home_dir File.dirname(@file) end |
#new_name ⇒ String
88 89 90 91 |
# File 'lib/pdfh/models/document.rb', line 88 def new_name new_name = type.generate_new_name(rename_data) "#{new_name}#{file_extension}" end |
#print_cmd ⇒ String
99 100 101 102 103 104 |
# File 'lib/pdfh/models/document.rb', line 99 def print_cmd return "N/A" if type.print_cmd.nil? || type.print_cmd.empty? relative_path = File.join(store_path, new_name) "#{type.print_cmd} #{relative_path}" end |
#print_info ⇒ void
This method returns an undefined value.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pdfh/models/document.rb', line 28 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 "Print CMD", print_cmd print_info_line "Processed?", "No (in Dry mode)" if Pdfh.dry? end |
#print_info_line(property, info) ⇒ void
This method returns an undefined value.
40 41 42 |
# File 'lib/pdfh/models/document.rb', line 40 def print_info_line(property, info) Pdfh.ident_print property, info.to_s, color: :light_blue, width: 12 end |
#rename_data ⇒ Hash{Symbol->String
Returns ].
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pdfh/models/document.rb', line 75 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
94 95 96 |
# File 'lib/pdfh/models/document.rb', line 94 def store_path type.generate_path(rename_data) end |
#sub_type ⇒ String
70 71 72 |
# File 'lib/pdfh/models/document.rb', line 70 def sub_type @sub_type&.name&.titleize || "N/A" end |
#type_name ⇒ String
65 66 67 |
# File 'lib/pdfh/models/document.rb', line 65 def type_name type&.name&.titleize || "N/A" end |