Class: Spellr::File

Inherits:
Pathname
  • Object
show all
Defined in:
lib/spellr/file.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.wrap(file) ⇒ Object



7
8
9
# File 'lib/spellr/file.rb', line 7

def self.wrap(file)
  file.is_a?(Spellr::File) ? file : Spellr::File.new(file)
end

Instance Method Details

#first_lineObject



18
19
20
# File 'lib/spellr/file.rb', line 18

def first_line
  @first_line ||= each_line.first
end

#fnmatch?(pattern) ⇒ Boolean



22
23
24
25
# File 'lib/spellr/file.rb', line 22

def fnmatch?(pattern)
  relative_path_from(Pathname.pwd).fnmatch?(pattern, ::File::FNM_DOTMATCH) ||
    Pathname.new(basename).fnmatch?(pattern, ::File::FNM_DOTMATCH)
end

#hashbangObject



11
12
13
14
15
16
# File 'lib/spellr/file.rb', line 11

def hashbang
  return if extname != ''
  return unless first_line&.start_with?('#!')

  first_line
end