Class: KyotoTycoon::Stream::Line

Inherits:
Struct
  • Object
show all
Defined in:
lib/kyototycoon/stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cmdObject

Returns the value of attribute cmd

Returns:

  • (Object)

    the current value of cmd



24
25
26
# File 'lib/kyototycoon/stream.rb', line 24

def cmd
  @cmd
end

#dbObject

Returns the value of attribute db

Returns:

  • (Object)

    the current value of db



24
25
26
# File 'lib/kyototycoon/stream.rb', line 24

def db
  @db
end

#raw_argsObject

Returns the value of attribute raw_args

Returns:

  • (Object)

    the current value of raw_args



24
25
26
# File 'lib/kyototycoon/stream.rb', line 24

def raw_args
  @raw_args
end

#sidObject

Returns the value of attribute sid

Returns:

  • (Object)

    the current value of sid



24
25
26
# File 'lib/kyototycoon/stream.rb', line 24

def sid
  @sid
end

#tsObject

Returns the value of attribute ts

Returns:

  • (Object)

    the current value of ts



24
25
26
# File 'lib/kyototycoon/stream.rb', line 24

def ts
  @ts
end

Instance Method Details

#argsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kyototycoon/stream.rb', line 25

def args
  @args ||= begin
    return [] if raw_args.nil?
    k,v = *raw_args.split("\t").map{|v| v.unpack('m').first}
    return [k] unless v
    xt = 0
    v.unpack('C5').each{|num|
      xt = (xt << 8) +  num
    }
    v = v[5, v.length]
    [k, v, xt]
  end
end

#keyObject



39
40
41
42
43
# File 'lib/kyototycoon/stream.rb', line 39

def key
  @key ||= begin
    args.first || nil
  end
end

#timeObject



69
70
71
# File 'lib/kyototycoon/stream.rb', line 69

def time
  @time ||= Time.at(*[ts[0,10], ts[10, ts.length]].map(&:to_i))
end

#valueObject



45
46
47
48
49
# File 'lib/kyototycoon/stream.rb', line 45

def value
  @value ||= begin
    args[1] || nil
  end
end

#xtObject



51
52
53
54
55
# File 'lib/kyototycoon/stream.rb', line 51

def xt
  @xt ||= begin
    args[2] || nil
  end
end

#xt_timeObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/kyototycoon/stream.rb', line 57

def xt_time
  @xt_time ||= begin
    if args[2]
      # if not set xt:
      # Time.at(1099511627775) # => 36812-02-20 09:36:15 +0900
      Time.at(args[2].to_i) 
    else
      Time.at(0)
    end
  end
end