Class: IMGParser

Inherits:
Parser show all
Defined in:
lib/Parsers/IMGParser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#setNext

Constructor Details

#initialize(isForJekyll) ⇒ IMGParser

Returns a new instance of IMGParser.



12
13
14
# File 'lib/Parsers/IMGParser.rb', line 12

def initialize(isForJekyll)
    @isForJekyll = isForJekyll
end

Instance Attribute Details

#isForJekyllObject

Returns the value of attribute isForJekyll.



10
11
12
# File 'lib/Parsers/IMGParser.rb', line 10

def isForJekyll
  @isForJekyll
end

#nextParserObject

Returns the value of attribute nextParser.



10
11
12
# File 'lib/Parsers/IMGParser.rb', line 10

def nextParser
  @nextParser
end

#pathPolicyObject

Returns the value of attribute pathPolicy.



10
11
12
# File 'lib/Parsers/IMGParser.rb', line 10

def pathPolicy
  @pathPolicy
end

Instance Method Details

#parse(paragraph) ⇒ Object



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
48
49
50
# File 'lib/Parsers/IMGParser.rb', line 16

def parse(paragraph)
    if paragraph.type == 'IMG'

        fileName = paragraph..id #d*fsafwfe.jpg

        imageURL = "https://miro.medium.com/max/1400/#{fileName}"

        imagePathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(paragraph.postID), pathPolicy.getRelativePath(paragraph.postID))
        absolutePath = imagePathPolicy.getAbsolutePath(fileName)
        
        result = ""
        alt = ""

        if  ImageDownloader.download(absolutePath, imageURL)
            relativePath = imagePathPolicy.getRelativePath(fileName)
            if isForJekyll
                result = "\r\n\r\n![#{paragraph.text}](/#{relativePath}#{alt})\r\n\r\n"
            else
                result = "\r\n\r\n![#{paragraph.text}](#{relativePath}#{alt})\r\n\r\n"
            end
        else
            result = "\r\n\r\n![#{paragraph.text}](#{imageURL}#{alt})\r\n\r\n"
        end

        if paragraph.text != ""
            result += "#{paragraph.text}\r\n"
        end

        result
    else
        if !nextParser.nil?
            nextParser.parse(paragraph)
        end
    end
end