Class: GrnMini::Hash

Inherits:
Table
  • Object
show all
Defined in:
lib/grn_mini/hash.rb

Instance Attribute Summary

Attributes inherited from Table

#grn

Instance Method Summary collapse

Methods inherited from Table

#each, #empty?, #group, #need_setup_columns?, #select, #setup_columns, #size, #sort, #value_type

Constructor Details

#initialize(name = "Hash") ⇒ Hash

Returns a new instance of Hash.



5
6
7
8
9
# File 'lib/grn_mini/hash.rb', line 5

def initialize(name = "Hash")
  super(name,
        Groonga[name] || Groonga::Hash.create(name: name, persistent: true),
        )
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
# File 'lib/grn_mini/hash.rb', line 16

def [](key)
  @grn[key]
end

#[]=(key, value) ⇒ Object



20
21
22
# File 'lib/grn_mini/hash.rb', line 20

def []=(key, value)
  add(key, value)
end

#add(key, values) ⇒ Object



11
12
13
14
# File 'lib/grn_mini/hash.rb', line 11

def add(key, values)
  setup_columns(values) if need_setup_columns?
  @grn.add(key, values)
end

#delete(id = nil, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/grn_mini/hash.rb', line 24

def delete(id = nil, &block)
  if block_given?
    @grn.delete(&block)
  else
    @grn.delete(id)
  end
end