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 |
# File 'lib/jubatus/common/datum.rb', line 11 def initialize(values = {}) @string_values = [] @num_values = [] @binary_values = [] values.each { |k, v| raise TypeError unless String === k 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.
81 82 83 |
# File 'lib/jubatus/common/datum.rb', line 81 def binary_values @binary_values end |
#num_values ⇒ Object (readonly)
Returns the value of attribute num_values.
81 82 83 |
# File 'lib/jubatus/common/datum.rb', line 81 def num_values @num_values end |
#string_values ⇒ Object (readonly)
Returns the value of attribute string_values.
81 82 83 |
# File 'lib/jubatus/common/datum.rb', line 81 def string_values @string_values end |
Class Method Details
Instance Method Details
#add_binary(key, value) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/jubatus/common/datum.rb', line 49 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
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jubatus/common/datum.rb', line 38 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
29 30 31 32 33 34 35 36 |
# File 'lib/jubatus/common/datum.rb', line 29 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
58 59 60 61 |
# File 'lib/jubatus/common/datum.rb', line 58 def to_msgpack(out = '') t = [@string_values, @num_values, @binary_values] return TYPE.to_msgpack(t) end |
#to_s ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/jubatus/common/datum.rb', line 72 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 |