Class: DohDb::AbstractRow
- Inherits:
-
Object
- Object
- DohDb::AbstractRow
show all
- Defined in:
- lib/dohmysql/abstract_row.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#keys ⇒ Object
Returns the value of attribute keys.
6
7
8
|
# File 'lib/dohmysql/abstract_row.rb', line 6
def keys
@keys
end
|
#values ⇒ Object
Returns the value of attribute values.
6
7
8
|
# File 'lib/dohmysql/abstract_row.rb', line 6
def values
@values
end
|
Instance Method Details
#at(index) ⇒ Object
9
10
11
|
# File 'lib/dohmysql/abstract_row.rb', line 9
def at(index)
@values.at(index)
end
|
#each_pair ⇒ Object
46
47
48
49
50
|
# File 'lib/dohmysql/abstract_row.rb', line 46
def each_pair
@keys.size.times do |index|
yield(@keys.at(index), @values.at(index))
end
end
|
#empty_field?(key) ⇒ Boolean
56
57
58
59
60
|
# File 'lib/dohmysql/abstract_row.rb', line 56
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/dohmysql/abstract_row.rb', line 13
def get(key)
index = @keys.index(key)
if index
@values.at(index)
else
nil
end
end
|
#inspect ⇒ Object
40
41
42
43
44
|
# File 'lib/dohmysql/abstract_row.rb', line 40
def inspect
ary = []
@keys.size.times {|index| ary.push([@keys[index], @values[index]])}
ary.inspect
end
|
#key?(key) ⇒ Boolean
23
24
25
|
# File 'lib/dohmysql/abstract_row.rb', line 23
def key?(key)
!@keys.index(key).nil?
end
|
#size ⇒ Object
52
53
54
|
# File 'lib/dohmysql/abstract_row.rb', line 52
def size
@keys.size
end
|
#to_a ⇒ Object
Also known as:
to_ary
27
28
29
30
31
|
# File 'lib/dohmysql/abstract_row.rb', line 27
def to_a
retval = []
@keys.size.times {|index| retval.push([@keys[index], @values[index]])}
retval
end
|
#to_h ⇒ Object
34
35
36
37
38
|
# File 'lib/dohmysql/abstract_row.rb', line 34
def to_h
retval = {}
@keys.each_with_index {|key, index| retval[key] = @values.at(index)}
retval
end
|