Class: Diary::Snippet

Inherits:
Object
  • Object
show all
Defined in:
lib/diary/snippet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Snippet

Returns a new instance of Snippet.



5
6
7
# File 'lib/diary/snippet.rb', line 5

def initialize(name)
  @path = File.join("snippets", "#{name}.html")
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/diary/snippet.rb', line 3

def path
  @path
end

Instance Method Details

#contentObject



9
10
11
12
13
14
15
16
17
# File 'lib/diary/snippet.rb', line 9

def content
  unless @content
    File.open(path, 'r') do |file|
      @content ||= file.read
    end
  end

  @content
end