Class: XeroGateway::Report::Row
- Inherits:
-
Object
- Object
- XeroGateway::Report::Row
show all
- Defined in:
- lib/xero_gateway/report/row.rb
Constant Summary
collapse
- COLUMN_METHOD_NAME_RE =
/^column\_([0-9])+$/
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(column_titles, columns, section_name = nil) ⇒ Row
Returns a new instance of Row.
8
9
10
11
12
13
|
# File 'lib/xero_gateway/report/row.rb', line 8
def initialize(column_titles, columns, section_name = nil)
@columns = columns
@column_titles = column_titles
@column_titles_underscored = column_titles.map(&:to_s).map(&:underscore)
@section_name = section_name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/xero_gateway/report/row.rb', line 27
def method_missing(method_name, *args, &block)
if method_name =~ COLUMN_METHOD_NAME_RE
ActiveSupport::Deprecation.warn("XeroGateway: The #column_n API for accessing report cells will be deprecated in a future version. Please use the underscored column title, a hash or array index accessor", caller_locations)
@columns[$1.to_i - 1]
elsif (column_index = @column_titles_underscored.index(method_name.to_s))
@columns[column_index]
else
super
end
end
|
Instance Attribute Details
#section_name ⇒ Object
Returns the value of attribute section_name.
6
7
8
|
# File 'lib/xero_gateway/report/row.rb', line 6
def section_name
@section_name
end
|
Instance Method Details
#[](key) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/xero_gateway/report/row.rb', line 15
def [](key)
return @columns[key] if key.is_a?(Integer)
[ @column_titles, @column_titles_underscored ].each do |names|
if index = names.index(key.to_s)
return @columns[index]
end
end
nil
end
|
#inspect ⇒ Object
43
44
45
|
# File 'lib/xero_gateway/report/row.rb', line 43
def inspect
"<XeroGateway::Report::Row:#{object_id} #{pairs}>"
end
|
#respond_to_missing?(method_name, *args) ⇒ Boolean
39
40
41
|
# File 'lib/xero_gateway/report/row.rb', line 39
def respond_to_missing?(method_name, *args)
(method_name =~ COLUMN_METHOD_NAME_RE) || @column_titles_underscored.include?(method_name.to_s) || super
end
|