Class: TreasureData::Command::MessagePackParser
- Inherits:
-
Object
- Object
- TreasureData::Command::MessagePackParser
- Defined in:
- lib/td/command/import.rb
Instance Method Summary collapse
- #call(file, path, &block) ⇒ Object
-
#initialize(time_key) ⇒ MessagePackParser
constructor
A new instance of MessagePackParser.
Constructor Details
#initialize(time_key) ⇒ MessagePackParser
Returns a new instance of MessagePackParser.
277 278 279 280 |
# File 'lib/td/command/import.rb', line 277 def initialize(time_key) require 'msgpack' @time_key = time_key end |
Instance Method Details
#call(file, path, &block) ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/td/command/import.rb', line 282 def call(file, path, &block) i = 0 MessagePack::Unpacker.new(file).each {|record| i += 1 begin unless record.is_a?(Hash) raise "record must be a Hash" end time = record[@time_key] unless time raise "record doesn't have '#{@time_key}' column" end case time when Integer # do nothing else time = Time.parse(time.to_s).to_i end record['time'] = time block.call(record) rescue $stderr.puts " skipped: #{$!}: #{record.to_json}" end } rescue EOFError end |