Class: DohDb::AbstractRow
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
Returns the value of attribute keys.
4
5
6
|
# File 'lib/doh/mysql/abstract_row.rb', line 4
def keys
@keys
end
|
Returns the value of attribute values.
4
5
6
|
# File 'lib/doh/mysql/abstract_row.rb', line 4
def values
@values
end
|
Instance Method Details
#at(index) ⇒ Object
9
10
11
|
# File 'lib/doh/mysql/abstract_row.rb', line 9
def at(index)
@values.at(index)
end
|
#each_pair ⇒ Object
45
46
47
48
49
|
# File 'lib/doh/mysql/abstract_row.rb', line 45
def each_pair
@keys.size.times do |index|
yield(@keys.at(index), @values.at(index))
end
end
|
#empty_field?(key) ⇒ Boolean
55
56
57
58
59
|
# File 'lib/doh/mysql/abstract_row.rb', line 55
def empty_field?(key)
return true if !key?(key)
val = get(key)
return val.nil? || (val.respond_to?(:empty?) && val.empty?)
end
|
#get(key) ⇒ Object
Also known as:
[]
13
14
15
16
17
18
19
20
|
# File 'lib/doh/mysql/abstract_row.rb', line 13
def get(key)
index = @keys.index(key)
if index
@values.at(index)
else
nil
end
end
|
39
40
41
42
43
|
# File 'lib/doh/mysql/abstract_row.rb', line 39
def inspect
ary = []
@keys.size.times {|index| ary.push([@keys[index], @values[index]])}
ary.inspect
end
|
#key?(key) ⇒ Boolean
23
24
25
|
# File 'lib/doh/mysql/abstract_row.rb', line 23
def key?(key)
!@keys.index(key).nil?
end
|
#record_id ⇒ Object
this should probably be removed eventually, but it’s here for now for backwards compatibility at least
62
63
64
|
# File 'lib/doh/mysql/abstract_row.rb', line 62
def record_id
get('id')
end
|
51
52
53
|
# File 'lib/doh/mysql/abstract_row.rb', line 51
def size
@keys.size
end
|
27
28
29
30
31
|
# File 'lib/doh/mysql/abstract_row.rb', line 27
def to_a
retval = []
@keys.size.times {|index| retval.push([@keys[index], @values[index]])}
retval
end
|
33
34
35
36
37
|
# File 'lib/doh/mysql/abstract_row.rb', line 33
def to_h
retval = {}
@keys.each_with_index {|key, index| retval[key] = @values.at(index)}
retval
end
|