Class: TreasureData::Command::MessagePackParser
- Inherits:
-
Object
- Object
- TreasureData::Command::MessagePackParser
- Defined in:
- lib/td/command/table.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.
705 706 707 708 |
# File 'lib/td/command/table.rb', line 705 def initialize(time_key) require 'msgpack' @time_key = time_key end |
Instance Method Details
#call(file, path, &block) ⇒ Object
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/td/command/table.rb', line 710 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 |