Class: Briefing::Slides

Inherits:
Object
  • Object
show all
Defined in:
lib/briefing/slides.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ Slides

Returns a new instance of Slides.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/briefing/slides.rb', line 8

def initialize(filepath)
  @sections = []
  buffer = []
  File.open(filepath).read.each_line {|line|
    if line.match /^-{3,}(.*)$/
      @sections << buffer.join('') if buffer.length > 0
      buffer = []
    else
      buffer << modify_assets_path(line)
    end
  }
  @sections << buffer.join('') if buffer.length > 0
  @options = Options.new(@sections.shift) if @sections.length > 0
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/briefing/slides.rb', line 6

def options
  @options
end

#sectionsObject (readonly)

Returns the value of attribute sections.



6
7
8
# File 'lib/briefing/slides.rb', line 6

def sections
  @sections
end

Instance Method Details

#modify_assets_path(line) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/briefing/slides.rb', line 23

def modify_assets_path(line)
  ## ![](hoge.jpg)  =>  ![](assets/hoge.jpg)
  line.gsub(/!\[(.*)\]\((.+)\)/) {|matched|
    alt = $1
    path = $2
    if path.match /^https?:\/\//
      matched
    elsif path.match /^assets\//
      matched
    else
      "![#{alt}](assets/#{CGI.escape(path)})"
    end
  }
end