Class: Cassandra::Types::Map
- Inherits:
-
Cassandra::Type
- Object
- Cassandra::Type
- Cassandra::Types::Map
- Defined in:
- lib/cassandra/types.rb
Instance Method Summary collapse
-
#assert(value, message = nil, &block) ⇒ void
Asserts that a given value is a Hash.
- #eql?(other) ⇒ Boolean (also: #==)
-
#kind ⇒ Symbol
:map
. -
#new(*value) ⇒ Hash
Coerces the value to Hash.
-
#to_s ⇒ String
"map<type, type>"
.
Instance Method Details
#assert(value, message = nil, &block) ⇒ void
This method returns an undefined value.
Asserts that a given value is a Hash
829 830 831 832 833 834 835 836 |
# File 'lib/cassandra/types.rb', line 829 def assert(value, = nil, &block) Util.assert_instance_of(::Hash, value, , &block) value.each do |k, v| Util.assert_type(@key_type, k, , &block) Util.assert_type(@value_type, v, , &block) end nil end |
#eql?(other) ⇒ Boolean Also known as: ==
844 845 846 847 848 |
# File 'lib/cassandra/types.rb', line 844 def eql?(other) other.is_a?(Map) && @key_type == other.key_type && @value_type == other.value_type end |
#kind ⇒ Symbol
Returns :map
.
791 792 793 |
# File 'lib/cassandra/types.rb', line 791 def kind :map end |
#new(*value) ⇒ Hash
Coerces the value to Hash
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
# File 'lib/cassandra/types.rb', line 799 def new(*value) value = value.first if value.one? case value when ::Hash value.each do |k, v| Util.assert_type(@key_type, k) Util.assert_type(@value_type, v) end value when ::Array result = ::Hash.new value.each_slice(2) do |(k, v)| Util.assert_type(@key_type, k) Util.assert_type(@value_type, v) result[k] = v end result else raise ::ArgumentError, "cannot convert #{value.inspect} to #{to_s}" end end |
#to_s ⇒ String
Returns "map<type, type>"
.
840 841 842 |
# File 'lib/cassandra/types.rb', line 840 def to_s "map<#{@key_type.to_s}, #{@value_type.to_s}>" end |