All the guts of a Section class inside a module, so multiple inheritance-like behaviour can be used for Reports which need both Section-like and Row < Calculator-like objects to keep per-section totals.
Initialize a section by passing in a unique identifier of your choice and a Project instance (may be nil if this section has no project or customer).
# File lib/track_record_sections.rb, line 44 def initialize_section( identifier, project ) @identifier = identifier @project = project @customer = project.try( :customer ) end
Returns a representation of the section title, based on the customer and project data passed to the constructor. Returns HTML-safe HTML data by default, or pass ‘true’ in the optional second parameter to return plain text only with no escaping (e.g. for CSV output, or any other non-HTML format).
The method requires access to helper functions, such as “link_to” or “ApplicationHelper”. This is done via a context object you pass in via the mandatory first parameter. If you’re calling here from ERB code in a view, simply pass “self” here:
<%= section.title( self ) %>
# File lib/track_record_sections.rb, line 63 def title( context, plain_text = false ) if ( @project.nil? ) return 'No customer, no project' elsif ( @customer.nil? ) if ( plain_text ) return "(No customer) #{ @project.title }" else return "(No customer) #{ context.apphelp_augmented_link( @project ) }".html_safe() end else if ( plain_text ) return "Customer #{ @customer.title } - #{ @project.title }" else return "Customer #{ context.apphelp_augmented_link( @customer ) } - #{ context.apphelp_augmented_link( @project ) }".html_safe() end end end