Class: DeclarativeGrid::Renderers::AbstractRenderer
- Inherits:
-
Object
- Object
- DeclarativeGrid::Renderers::AbstractRenderer
- Defined in:
- lib/declarative_grid/renderers/abstract_renderer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Attributes.
-
#records ⇒ Object
Attributes.
Class Method Summary collapse
-
.grid_class ⇒ Object
Attributes of class.
- .grid_class=(k) ⇒ Object
- .inherited(subclass) ⇒ Object
- .options ⇒ Object
- .options=(opt) ⇒ Object
Instance Method Summary collapse
-
#columns ⇒ Object
Return selected columns to render.
-
#each_record ⇒ Object
Return enumerator of self.records.
-
#each_row ⇒ Object
Return enumerator of rows.
-
#headers ⇒ Object
Return array of localized headers.
-
#initialize(records, options = {}) ⇒ AbstractRenderer
constructor
Constructor.
-
#inspect ⇒ Object
Prevent from @records dumping.
-
#perform(io) ⇒ Object
Render data to the stream.
-
#to_string ⇒ Object
Render to string.
Constructor Details
#initialize(records, options = {}) ⇒ AbstractRenderer
Constructor
PARAM: records is an object representing the records of model
it can be:
1) Enumerator
2) Enumerable
PARAM: options is a hash object containing optional configuration
:columns => an array of column names to render
30 31 32 33 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 30 def initialize(records, = {}) self.records = records self. = self.class..merge end |
Instance Attribute Details
#options ⇒ Object
Attributes
17 18 19 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 17 def @options end |
#records ⇒ Object
Attributes
17 18 19 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 17 def records @records end |
Class Method Details
.grid_class ⇒ Object
Attributes of class
6 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 6 def self.grid_class; @grid_class; end |
.grid_class=(k) ⇒ Object
7 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 7 def self.grid_class=(k); @grid_class = k; end |
.inherited(subclass) ⇒ Object
11 12 13 14 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 11 def self.inherited(subclass) super(subclass) subclass. = self..dup end |
.options ⇒ Object
8 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 8 def self.; @options ||= {}; end |
.options=(opt) ⇒ Object
9 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 9 def self.(opt); @options = opt; end |
Instance Method Details
#columns ⇒ Object
Return selected columns to render
36 37 38 39 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 36 def columns names = [:columns] || [] self.class.grid_class.columns(*names) end |
#each_record ⇒ Object
Return enumerator of self.records
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 56 def each_record if block_given? case records when Enumerator, Enumerable then records.each{|r| yield r } else raise RendererError, "#{records}: invalid type" end else Enumerator.new self, :each_record end end |
#each_row ⇒ Object
Return enumerator of rows
47 48 49 50 51 52 53 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 47 def each_row if block_given? self.each_record{|r| yield row_for(r) } else Enumerator.new self, :each_row end end |
#headers ⇒ Object
Return array of localized headers
42 43 44 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 42 def headers self.columns.map(&:header) end |
#inspect ⇒ Object
Prevent from @records dumping
68 69 70 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 68 def inspect self.class.inspect end |
#perform(io) ⇒ Object
Render data to the stream
73 74 75 76 77 78 79 80 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 73 def perform(io) # # io.write string1 # io.puts string2 # ... # raise NotImplementedError end |
#to_string ⇒ Object
Render to string
83 84 85 86 87 88 |
# File 'lib/declarative_grid/renderers/abstract_renderer.rb', line 83 def to_string io = StringIO.new self.perform(io) io.close io.string end |