Class: DataFile
- Inherits:
-
Object
- Object
- DataFile
- Defined in:
- lib/sqs_cli/data_file.rb
Instance Method Summary collapse
-
#initialize(filename) ⇒ DataFile
constructor
A new instance of DataFile.
- #read_batches ⇒ Object
- #write_batch(batch) ⇒ Object
Constructor Details
#initialize(filename) ⇒ DataFile
Returns a new instance of DataFile.
5 6 7 |
# File 'lib/sqs_cli/data_file.rb', line 5 def initialize(filename) @filename = filename end |
Instance Method Details
#read_batches ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/sqs_cli/data_file.rb', line 9 def read_batches count = 0 File.readlines(@filename).each_slice(10).each do |batch| yield (batch.map { || count += 1 OpenStruct.new( message_id: count.to_s, body: Base64.strict_decode64(.strip) ) }) end end |
#write_batch(batch) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/sqs_cli/data_file.rb', line 22 def write_batch(batch) File.open(@filename, "a") do |f| batch.each do || f.puts Base64.strict_encode64(.body.strip) end end end |