Class: CodeSnippet::Snip
- Inherits:
-
Object
- Object
- CodeSnippet::Snip
- Defined in:
- lib/code_snippet/snip.rb
Overview
Snip is a file with a code snippet
Instance Attribute Summary collapse
-
#ext ⇒ Object
readonly
Returns the value of attribute ext.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(path, name, ext) ⇒ Snip
constructor
A new instance of Snip.
- #name ⇒ Object
Constructor Details
#initialize(path, name, ext) ⇒ Snip
Returns a new instance of Snip.
14 15 16 17 18 |
# File 'lib/code_snippet/snip.rb', line 14 def initialize(path, name, ext) @path = path @name = name @ext = ext end |
Instance Attribute Details
#ext ⇒ Object (readonly)
Returns the value of attribute ext.
4 5 6 |
# File 'lib/code_snippet/snip.rb', line 4 def ext @ext end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/code_snippet/snip.rb', line 4 def path @path end |
Class Method Details
.new_from_file(path) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/code_snippet/snip.rb', line 6 def self.new_from_file(path) new( path, File.basename(path), File.extname(path) ) end |
Instance Method Details
#content ⇒ Object
29 30 31 32 33 |
# File 'lib/code_snippet/snip.rb', line 29 def content raise 'cannot read snippet code' unless exist? File.read(@path) end |
#exist? ⇒ Boolean
25 26 27 |
# File 'lib/code_snippet/snip.rb', line 25 def exist? File.exist?(@path) end |
#name ⇒ Object
20 21 22 23 |
# File 'lib/code_snippet/snip.rb', line 20 def name @name .gsub(@ext, '') end |