class CodeSnippet::Snip

Snip is a file with a code snippet

Attributes

ext[R]
path[R]

Public Class Methods

new(path, name, ext) click to toggle source
# File lib/code_snippet/snip.rb, line 14
def initialize(path, name, ext)
  @path = path
  @name = name
  @ext = ext
end
new_from_file(path) click to toggle source
# File lib/code_snippet/snip.rb, line 6
def self.new_from_file(path)
  new(
    path,
    File.basename(path),
    File.extname(path)
  )
end

Public Instance Methods

content() click to toggle source
# File lib/code_snippet/snip.rb, line 29
def content
  raise 'cannot read snippet code' unless exist?

  File.read(@path)
end
exist?() click to toggle source
# File lib/code_snippet/snip.rb, line 25
def exist?
  File.exist?(@path)
end
name() click to toggle source
# File lib/code_snippet/snip.rb, line 20
def name
  @name
    .gsub(@ext, '')
end