Sha256: 93736fb5ea2976f3adc1ef7e6b43af8f740162cdd54458853c0c88e464b51e72

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

module Terminal
  class Table
    # A Style object holds all the formatting information for a Table object
    # 
    # To create a table with a certain style, use either the constructor 
    # option <tt>:style</tt>, the Table#style object or the Table#style= method
    #
    # All these examples have the same effect:
    # 
    #     # by constructor
    #     @table = Table.new(:style => {:padding_left => 2, :width => 40})
    #
    #     # by object
    #     @table.style.padding_left = 2
    #     @table.style.width = 40
    #
    #     # by method
    #     @table.style = {:padding_left => 2, :width => 40}
    # 
    # To set a default style for all tables created afterwards use Style.defaults=
    # 
    #     Terminal::Table::Style.defaults = {:width => 80}
    #
    class Style
      @@defaults = {
        :border_x => "-", :border_y => "|", :border_i => "+",
        :padding_left => 1, :padding_right => 1,
        :width => nil
      }
      
      attr_accessor :border_x
      attr_accessor :border_y
      attr_accessor :border_i
      
      attr_accessor :padding_left
      attr_accessor :padding_right
      
      attr_accessor :width
      
      
      def initialize options = {}
        apply self.class.defaults.merge(options)
      end
      
      def apply options
        options.each { |m, v| __send__ "#{m}=", v }
      end
      
      class << self
        def defaults
          @@defaults
        end
        
        def defaults= options
          @@defaults = defaults.merge(options)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
cft_smartcloud-0.3.3 lib/terminal-table-1.4.4/lib/terminal-table/style.rb
cft_smartcloud-0.3.2 lib/terminal-table-1.4.4/lib/terminal-table/style.rb
terminal-table-1.4.5 lib/terminal-table/style.rb
cft_smartcloud-0.3.1 lib/terminal-table-1.4.4/lib/terminal-table/style.rb
cft_smartcloud-0.3.0 lib/terminal-table-1.4.4/lib/terminal-table/style.rb
terminal-table-1.4.4 lib/terminal-table/style.rb