Class: PPtxt

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

Defined Under Namespace

Classes: Error, PPtxtSlide

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pptx) ⇒ PPtxt

Returns a new instance of PPtxt.



66
67
68
69
70
71
72
73
74
# File 'lib/pptxt.rb', line 66

def initialize(pptx)
    if (!Pathname.new(pptx).expand_path.exist?)
        raise PPtxt::Error::FileNotFound.new(pptx)
    end

    @pptx = pptx
    @slides = Array.new
    create_slides
end

Instance Attribute Details

#slidesObject

Returns the value of attribute slides.



4
5
6
# File 'lib/pptxt.rb', line 4

def slides
  @slides
end

Class Method Details

.configure_git(global = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pptxt.rb', line 6

def self.configure_git(global = false)
    if (ScoobyDoo.where_are_you("git").nil?)
        raise PPtxt::Error::MissingDependency.new("git")
    end

    # Configure git
    flag = ""
    flag = "--global" if (global)
    system(
        "git config #{flag} diff.pptxt.textconv \"pptxt --git\""
    )

    # Setup .gitattributes
    filename = ".gitattributes"
    if (global)
        cfg = "git config --global core.attributesfile"
        filename = %x(#{cfg}).strip
        if (filename.nil? || filename.empty?)
            filename = "~/.gitattributes"
            system("#{cfg} \"#{filename}\"")
        end
    end
    new_line = "*.pptx diff=pptxt\n"

    file = Pathname.new(filename).expand_path
    if (file.exist?)
        File.open(file) do |f|
            f.each_line do |line|
                if (line == new_line)
                    return
                end
            end
        end
        File.open(file, "a") do |f|
            f.write(new_line)
        end
    else
        File.open(file, "w") do |f|
            f.write(new_line)
        end
    end
end