Sha256: 00bc3bbde68b0e8808d38f55f6e53a4150185c1b09a4b0d2e8f794376a31076f

Contents?: true

Size: 1.41 KB

Versions: 16

Compression:

Stored size: 1.41 KB

Contents

# encoding: utf-8
module LocalPac
  module ProxyPac
    class HTMLDivStyle
      private

      attr_reader :data, :main_container_css_class, :element_container_css_class

      public

      def initialize(options = {})
        @main_container_css_class    = options.fetch(:main_container_css_class)
        @element_container_css_class = options.fetch(:element_container_css_class)
        @data                        = []
      rescue KeyError => e
        raise ArgumentError, e.message
      end

      def add_data(data)
        @data << data
      end

      def to_s
        data_row = data.reduce([]) do |memo, element|
          memo << "  <div class=\"#{element_container_css_class}\">"

          if element.header
            memo << "    <div class=\"#{element.header_css_class}\">" if element.header_css_class
            memo << "    #{element.header}"
            memo << '    </div>'                                      if element.header_css_class
          end

          memo << "    <div class=\"#{element.element_css_class}\">" if element.element_css_class
          memo << "      #{element.element}"
          memo << '    </div>'                                      if element.element_css_class

          memo << '  </div>'
        end

        content = ["<div class=\"#{main_container_css_class}\">"]
        content.concat data_row
        content << '</div>'

        content.join("\n")
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
local_pac-0.10.2 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.10.1 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.10.0 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.9.0 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.7.0 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.6.3 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.6.2 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.6.1 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.5.0 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.4.0 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.3.0 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.2.3 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.2.2 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.2.1 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.2.0 lib/local_pac/proxy_pac/html_div_style.rb
local_pac-0.1.13 lib/local_pac/proxy_pac/html_div_style.rb