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



20
21
22
# File 'lib/spellr/file.rb', line 20

def first_line
  @first_line ||= each_line.first
end

#hashbangObject



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

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

    first_line
  end
end

#insert(string, range) ⇒ Object



28
29
30
31
32
33
# File 'lib/spellr/file.rb', line 28

def insert(string, range)
  read_write do |body|
    body[range] = string
    body
  end
end

#read_writeObject



35
36
37
# File 'lib/spellr/file.rb', line 35

def read_write
  write(yield read)
end

#relative_pathObject



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

def relative_path
  @relative_path ||= relative_path_from(Spellr.config.pwd)
end