Class: IMGParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Parser

#initialize, #setNext

Constructor Details

This class inherits a constructor from Parser

Instance Attribute Details

#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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/Parsers/IMGParser.rb', line 11

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

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

        imageURL = "https://miro.medium.com/max/1400/#{paragraph.metadata.id}"

        imagePathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(nil), paragraph.postID)
        absolutePath = imagePathPolicy.getAbsolutePath(fileName)
        
        if  ImageDownloader.download(absolutePath, imageURL)
            relativePath = "#{pathPolicy.getRelativePath(nil)}/#{imagePathPolicy.getRelativePath(fileName)}"
            "![#{paragraph.text}](#{relativePath} \"#{paragraph.text}\")"
        else
            "![#{paragraph.text}](#{imageURL} \"#{paragraph.text}\")"
        end
    else
        if !nextParser.nil?
            nextParser.parse(paragraph)
        end
    end
end