Class: Jubatus::Common::Datum
- Inherits:
-
Object
- Object
- Jubatus::Common::Datum
- Includes:
- Jubatus::Common
- Defined in:
- lib/jubatus/common/datum.rb
Constant Summary collapse
- TYPE =
TTuple.new(TList.new(TTuple.new(TString.new, TString.new)), TList.new(TTuple.new(TString.new, TFloat.new)), TList.new(TTuple.new(TString.new, TString.new)))
Instance Attribute Summary collapse
-
#binary_values ⇒ Object
readonly
Returns the value of attribute binary_values.
-
#num_values ⇒ Object
readonly
Returns the value of attribute num_values.
-
#string_values ⇒ Object
readonly
Returns the value of attribute string_values.
Class Method Summary collapse
Instance Method Summary collapse
- #add_binary(key, value) ⇒ Object
- #add_number(key, value) ⇒ Object
- #add_string(key, value) ⇒ Object
-
#initialize(values = {}) ⇒ Datum
constructor
A new instance of Datum.
- #to_msgpack(out = '') ⇒ Object
- #to_s ⇒ Object
Methods included from Jubatus::Common
Constructor Details
#initialize(values = {}) ⇒ Datum
Returns a new instance of Datum.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jubatus/common/datum.rb', line 11 def initialize(values = {}) @string_values = [] @num_values = [] @binary_values = [] values.each { |key, v| raise TypeError unless String === key || Symbol === key k = key.to_s if String === v @string_values << [k, v] elsif Integer === v @num_values << [k, v.to_f] elsif Float === v @num_values << [k, v] else raise TypeError end } end |
Instance Attribute Details
#binary_values ⇒ Object (readonly)
Returns the value of attribute binary_values.
82 83 84 |
# File 'lib/jubatus/common/datum.rb', line 82 def binary_values @binary_values end |
#num_values ⇒ Object (readonly)
Returns the value of attribute num_values.
82 83 84 |
# File 'lib/jubatus/common/datum.rb', line 82 def num_values @num_values end |
#string_values ⇒ Object (readonly)
Returns the value of attribute string_values.
82 83 84 |
# File 'lib/jubatus/common/datum.rb', line 82 def string_values @string_values end |
Class Method Details
Instance Method Details
#add_binary(key, value) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/jubatus/common/datum.rb', line 50 def add_binary(key, value) raise TypeError unless String === key if String === value @binary_values << [key, value] else raise TypeError end end |
#add_number(key, value) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/jubatus/common/datum.rb', line 39 def add_number(key, value) raise TypeError unless String === key if Integer === value @num_values << [key, value.to_f] elsif Float === value @num_values << [key, value] else raise TypeError end end |
#add_string(key, value) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/jubatus/common/datum.rb', line 30 def add_string(key, value) raise TypeError unless String === key if String === value @string_values << [key, value] else raise TypeError end end |
#to_msgpack(out = '') ⇒ Object
59 60 61 62 |
# File 'lib/jubatus/common/datum.rb', line 59 def to_msgpack(out = '') t = [@string_values, @num_values, @binary_values] return TYPE.to_msgpack(t) end |
#to_s ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/jubatus/common/datum.rb', line 73 def to_s gen = Jubatus::Common::MessageStringGenerator.new gen.open("datum") gen.add("string_values", @string_values) gen.add("num_values", @num_values) gen.add("binary_values", @binary_values) gen.close() return gen.to_s end |