Class: Differin::File
- Inherits:
-
Object
- Object
- Differin::File
- Defined in:
- lib/differin/file.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Getters.
Instance Method Summary collapse
- #extension ⇒ Object
- #filename ⇒ Object
-
#initialize(file) ⇒ File
constructor
A new instance of File.
- #lines ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(file) ⇒ File
Returns a new instance of File.
7 8 9 10 |
# File 'lib/differin/file.rb', line 7 def initialize(file) @file = load_file(file) fail Differin::InvalidFile unless valid? end |
Instance Attribute Details
#file ⇒ Object
Getters
5 6 7 |
# File 'lib/differin/file.rb', line 5 def file @file end |
Instance Method Details
#extension ⇒ Object
16 17 18 |
# File 'lib/differin/file.rb', line 16 def extension ::File.extname(file.path).delete('.') end |
#filename ⇒ Object
12 13 14 |
# File 'lib/differin/file.rb', line 12 def filename ::File.basename(file.path) end |
#lines ⇒ Object
20 21 22 23 |
# File 'lib/differin/file.rb', line 20 def lines return @lines if defined?(@lines) @lines = readlines end |
#valid? ⇒ Boolean
25 26 27 28 |
# File 'lib/differin/file.rb', line 25 def valid? return false unless ALLOWED_EXTENSIONS.include?(extension) true end |