Class: GcodeThumbnailExtractorService
- Inherits:
-
Object
- Object
- GcodeThumbnailExtractorService
- Defined in:
- app/services/gcode_thumbnail_extractor_service.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(file:) ⇒ GcodeThumbnailExtractorService
constructor
A new instance of GcodeThumbnailExtractorService.
Constructor Details
#initialize(file:) ⇒ GcodeThumbnailExtractorService
Returns a new instance of GcodeThumbnailExtractorService.
2 3 4 5 |
# File 'app/services/gcode_thumbnail_extractor_service.rb', line 2 def initialize(file:) @file = file @remaining = nil end |
Instance Method Details
#call ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/gcode_thumbnail_extractor_service.rb', line 7 def call data = "" while (line = @file.gets("\n")) if @remaining.nil? if line =~ /thumbnail[^\n]*begin[^\n]*? ([0-9]+)$/ @remaining = $1.to_i end elsif line =~ /thumbnail[^\n]*end$/ || @remaining <= 0 @remaining = nil break else new_data = line.gsub(/^;\s*/, "").chomp data += new_data @remaining -= new_data.length end end StringIO.new(Base64.strict_decode64(data)) end |