Class: ResultSet
- Inherits:
-
Object
show all
- Defined in:
- lib/marjoree/result_set.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(statement, output_param_names = []) ⇒ ResultSet
Returns a new instance of ResultSet.
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/marjoree/result_set.rb', line 5
def initialize(statement, output_param_names = [])
@padding = " "
@spacer = " "
@columns = statement.columns
@hashes = []
if output_param_names.length > 0
apply_output_params output_param_names, statement
else
statement
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/marjoree/result_set.rb', line 25
def method_missing(name)
member_var = eval("@#{name}")
if !member_var.nil?
return member_var
else
return super
end
end
|
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
2
3
4
|
# File 'lib/marjoree/result_set.rb', line 2
def columns
@columns
end
|
#hashes ⇒ Object
Returns the value of attribute hashes.
3
4
5
|
# File 'lib/marjoree/result_set.rb', line 3
def hashes
@hashes
end
|
Instance Method Details
#apply_output_params(output_param_names, statement) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/marjoree/result_set.rb', line 18
def apply_output_params(output_param_names, statement)
output_param_names.each do |output_param_name|
instance_variable_set(output_param_name, statement.fetch![0])
statement.more_results
end
end
|
#collect ⇒ Object
50
51
52
53
54
|
# File 'lib/marjoree/result_set.rb', line 50
def collect
@hashes.each do |hash|
yield hash
end
end
|
#contains?(*expected_rows) ⇒ Boolean
60
61
62
63
64
65
66
|
# File 'lib/marjoree/result_set.rb', line 60
def contains?(*expected_rows)
expected_rows.flatten.each do |expected|
return false unless contains_row?(expected)
end
return true
end
|
#contains_row?(expected) ⇒ Boolean
68
69
70
71
72
73
74
75
|
# File 'lib/marjoree/result_set.rb', line 68
def contains_row?(expected)
expected_with_symbols = convert_keys_to_symbols(expected)
@hashes.each do |actual|
return true if actual == actual.merge(expected_with_symbols)
end
return false
end
|
#count ⇒ Object
38
39
40
|
# File 'lib/marjoree/result_set.rb', line 38
def count
return @hashes.size
end
|
#empty? ⇒ Boolean
46
47
48
|
# File 'lib/marjoree/result_set.rb', line 46
def empty?
return count == 0
end
|
#has?(expected_result_set) ⇒ Boolean
56
57
58
|
# File 'lib/marjoree/result_set.rb', line 56
def has?(expected_result_set)
return contains?(expected_result_set.row_hashes)
end
|
#is_output_param?(name) ⇒ Boolean
34
35
36
|
# File 'lib/marjoree/result_set.rb', line 34
def is_output_param?(name)
return !eval("#{name}").nil?
end
|
#size ⇒ Object
42
43
44
|
# File 'lib/marjoree/result_set.rb', line 42
def size
return count
end
|
#to_s ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/marjoree/result_set.rb', line 77
def to_s
column_widths = widest_value_in_columns
result = (column_widths)
result << "\n" + create_separator_row(column_widths)
@hashes.each { |row| result << "\n" + create_data_row(row, column_widths) }
return result
end
|