Class: IMGParser
Instance Attribute Summary collapse
-
#isForJekyll ⇒ Object
Returns the value of attribute isForJekyll.
-
#nextParser ⇒ Object
Returns the value of attribute nextParser.
-
#pathPolicy ⇒ Object
Returns the value of attribute pathPolicy.
Instance Method Summary collapse
-
#initialize(isForJekyll, skipImages: false) ⇒ IMGParser
constructor
When ‘skipImages: true`, parse() emits the remote miro URL directly without calling ImageDownloader.download or touching pathPolicy.
- #parse(paragraph) ⇒ Object
Methods inherited from Parser
Constructor Details
#initialize(isForJekyll, skipImages: false) ⇒ IMGParser
When ‘skipImages: true`, parse() emits the remote miro URL directly without calling ImageDownloader.download or touching pathPolicy. Used by –stdout / –list rendering paths in ZMediumFetcher.
13 14 15 16 |
# File 'lib/Parsers/IMGParser.rb', line 13 def initialize(isForJekyll, skipImages: false) @isForJekyll = isForJekyll @skipImages = skipImages end |
Instance Attribute Details
#isForJekyll ⇒ Object
Returns the value of attribute isForJekyll.
8 9 10 |
# File 'lib/Parsers/IMGParser.rb', line 8 def isForJekyll @isForJekyll end |
#nextParser ⇒ Object
Returns the value of attribute nextParser.
8 9 10 |
# File 'lib/Parsers/IMGParser.rb', line 8 def nextParser @nextParser end |
#pathPolicy ⇒ Object
Returns the value of attribute pathPolicy.
8 9 10 |
# File 'lib/Parsers/IMGParser.rb', line 8 def pathPolicy @pathPolicy end |
Instance Method Details
#parse(paragraph) ⇒ Object
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 51 52 53 54 55 56 57 |
# File 'lib/Parsers/IMGParser.rb', line 18 def parse(paragraph) if paragraph.type == 'IMG' fileName = paragraph..id #d*fsafwfe.jpg miro_host = ENV.fetch('MIRO_MEDIUM_HOST', 'https://miro.medium.com') imageURL = "#{miro_host}/#{fileName}" result = "" alt = "" if @skipImages result = "\r\n\r\n\r\n\r\n" else imagePathPolicy = PathPolicy.new(pathPolicy.getAbsolutePath(paragraph.postID), pathPolicy.getRelativePath(paragraph.postID)) absolutePath = imagePathPolicy.getAbsolutePath(fileName) if ImageDownloader.download(absolutePath, imageURL) relativePath = imagePathPolicy.getRelativePath(fileName) if isForJekyll result = "\r\n\r\n\r\n\r\n" else result = "\r\n\r\n\r\n\r\n" end else result = "\r\n\r\n\r\n\r\n" end end if paragraph.text != "" result += "#{paragraph.text}\r\n" end result else if !nextParser.nil? nextParser.parse(paragraph) end end end |