Sha256: 8fbfd8b130b3e8c4fb262a877ed3de1aeee96dc390e85a39b29cd0bc7221fdd0

Contents?: true

Size: 1.55 KB

Versions: 17

Compression:

Stored size: 1.55 KB

Contents

require_dependency "renalware/pathology"

module Renalware
  module Pathology
    # Responsible for rendering a HTML table for recent observation results.
    #
    class CurrentObservationResults::HTMLTableView < SimpleDelegator
      def render(view_model)
        header, *body = view_model

        content_tag(:div) do
          slice_size = calculate_slice_size(body.size)
          body.each_slice(slice_size) do |partial_body|
            concat(build_table(header, partial_body))
          end
        end
      end

      private

      def calculate_slice_size(number)
        (number.to_f / number_of_columns).ceil
      end

      def number_of_columns
        3
      end

      def build_table(header, body)
        content_tag(:table, id: "observations", class: "current-observations") do
          concat(format_header(header))
          concat(format_body(body))
        end
      end

      def format_header(cells)
        content_tag(:thead) do
          content_tag(:tr) do
            cells.each do |cell|
              concat(format_header_cell(cell))
            end
          end
        end
      end

      def format_body(rows)
        content_tag(:tbody) do
          rows.each do |row|
            concat(content_tag(:tr) do
              row.each do |cell|
                concat(format_body_cell(cell))
              end
            end)
          end
        end
      end

      def format_header_cell(cell)
        content_tag(:th, cell)
      end

      def format_body_cell(cell)
        content_tag(:td, cell.content)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
renalware-core-2.0.0.pre.rc9 app/presenters/renalware/pathology/current_observation_results.dead/html_table_view.rb.dead
renalware-core-2.0.0.pre.rc8 app/presenters/renalware/pathology/current_observation_results.dead/html_table_view.rb.dead
renalware-core-2.0.0.pre.rc7 app/presenters/renalware/pathology/current_observation_results.dead/html_table_view.rb.dead
renalware-core-2.0.0.pre.rc6 app/presenters/renalware/pathology/current_observation_results.dead/html_table_view.rb.dead
renalware-core-2.0.0.pre.rc5 app/presenters/renalware/pathology/current_observation_results.dead/html_table_view.rb.dead
renalware-core-2.0.0.pre.rc4 app/presenters/renalware/pathology/current_observation_results.dead/html_table_view.rb.dead
renalware-core-2.0.0.pre.rc3 app/presenters/renalware/pathology/current_observation_results.dead/html_table_view.rb.dead
renalware-core-2.0.0.pre.rc1 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
renalware-core-2.0.0.pre.beta12 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
renalware-core-2.0.0.pre.beta11 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
renalware-core-2.0.0.pre.beta10 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
renalware-core-2.0.0.pre.beta9 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
renalware-core-2.0.0.pre.beta8 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
renalware-core-2.0.0.pre.beta7 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
renalware-core-2.0.0.pre.beta6 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
renalware-core-2.0.0.pre.beta5 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb
renalware-core-2.0.0.pre.beta4 app/presenters/renalware/pathology/current_observation_results/html_table_view.rb