Class: Pdfh::FileInfo
- Inherits:
-
Object
- Object
- Pdfh::FileInfo
- Defined in:
- lib/pdfh/utils/file_info.rb
Overview
Encapsulates file system metadata for a PDF file path. Responsible for all file name derivations (extension, base name, backup name, etc.).
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
Full path to the file.
Instance Method Summary collapse
-
#backup_name ⇒ String
Backup file name with .bkp extension (e.g., "cuenta.pdf.bkp").
-
#dir ⇒ String
Directory path containing the file.
-
#extension ⇒ String
File extension including the dot (e.g., ".pdf").
- #initialize(file_path) ⇒ self constructor
-
#name ⇒ String
Complete file name (e.g., "cuenta.pdf").
-
#stem ⇒ String
(also: #name_only)
File name without extension (e.g., "cuenta").
-
#to_s ⇒ String
File name.
Constructor Details
#initialize(file_path) ⇒ self
9 10 11 |
# File 'lib/pdfh/utils/file_info.rb', line 9 def initialize(file_path) @path = file_path.to_s end |
Instance Attribute Details
#path ⇒ String (readonly)
Returns Full path to the file.
14 15 16 |
# File 'lib/pdfh/utils/file_info.rb', line 14 def path @path end |
Instance Method Details
#backup_name ⇒ String
Returns Backup file name with .bkp extension (e.g., "cuenta.pdf.bkp").
33 34 35 |
# File 'lib/pdfh/utils/file_info.rb', line 33 def backup_name "#{name}.bkp" end |
#dir ⇒ String
Returns Directory path containing the file.
38 39 40 |
# File 'lib/pdfh/utils/file_info.rb', line 38 def dir File.dirname(@path) end |
#extension ⇒ String
Returns File extension including the dot (e.g., ".pdf").
23 24 25 |
# File 'lib/pdfh/utils/file_info.rb', line 23 def extension File.extname(@path) end |
#name ⇒ String
Returns Complete file name (e.g., "cuenta.pdf").
28 29 30 |
# File 'lib/pdfh/utils/file_info.rb', line 28 def name File.basename(@path) end |
#stem ⇒ String Also known as: name_only
Returns File name without extension (e.g., "cuenta").
17 18 19 |
# File 'lib/pdfh/utils/file_info.rb', line 17 def stem File.basename(@path, extension) end |
#to_s ⇒ String
Returns File name.
43 44 45 |
# File 'lib/pdfh/utils/file_info.rb', line 43 def to_s name end |