Class: Hbase::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_record/connection_adapters/hbase/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result = {'fields' => [], 'results' => []}) ⇒ Result

Keeping this just in case, for now def self.new(result = => [], ‘results’ => [])

return nil if result['fields'].length < 1 && result['results'].length < 1

super

end



16
17
18
19
# File 'lib/active_record/connection_adapters/hbase/result.rb', line 16

def initialize(result = {'fields' => [], 'results' => []})
  @result = result
  @members = @result['results']
end

Instance Attribute Details

#membersObject

Returns the value of attribute members.



7
8
9
# File 'lib/active_record/connection_adapters/hbase/result.rb', line 7

def members
  @members
end

Instance Method Details

#countObject Also known as: size



46
47
48
# File 'lib/active_record/connection_adapters/hbase/result.rb', line 46

def count
  @result['results'].length
end

#each(arg_hash = {}, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/active_record/connection_adapters/hbase/result.rb', line 31

def each(arg_hash = {},&block)
  unless arg_hash[:as].nil?
    symbolize_keys = (arg_hash[:symbolize_keys].nil?) ? false : arg_hash[:symbolize_keys]
    if arg_hash[:as] == :hash
      hasherize_rows(symbolize_keys).each &block
    end
  else
    @result['results'].each &block
  end
end

#fieldsObject



42
43
44
# File 'lib/active_record/connection_adapters/hbase/result.rb', line 42

def fields
  @result['fields']
end

#hasherize_rows(symbolize_keys = false) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/active_record/connection_adapters/hbase/result.rb', line 21

def hasherize_rows(symbolize_keys = false)
  if symbolize_keys
    keys = @result['fields'].map! { |v| v.to_sym }
  else
    keys = @result['fields']
  end
  #binding.pry
  hashed_rows = @result['results'].map { |row| Hash[keys.zip row] }
end