class Differin::File
Attributes
file[RW]
Getters
Public Class Methods
new(file)
click to toggle source
# File lib/differin/file.rb, line 7 def initialize(file) @file = load_file(file) fail Differin::InvalidFile unless valid? end
Public Instance Methods
extension()
click to toggle source
# File lib/differin/file.rb, line 16 def extension ::File.extname(file.path).delete('.') end
filename()
click to toggle source
# File lib/differin/file.rb, line 12 def filename ::File.basename(file.path) end
lines()
click to toggle source
# File lib/differin/file.rb, line 20 def lines return @lines if defined?(@lines) @lines = readlines end
valid?()
click to toggle source
# File lib/differin/file.rb, line 25 def valid? return false unless ALLOWED_EXTENSIONS.include?(extension) true end
Private Instance Methods
load_file(file)
click to toggle source
# File lib/differin/file.rb, line 35 def load_file(file) return file if file.is_a?(::File) fail Differin::FileNotFound unless ::File.exist?(file.to_s) ::File.open(file.to_s, 'r') end
readlines()
click to toggle source
# File lib/differin/file.rb, line 42 def readlines file.readlines.map do |line| line.delete("\r").delete("\n") end end