Sha256: e0a77ac04e755805c6c164603ebf815a84d48e33991a7c910c13566496fe5921

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 KB

Contents

# encoding: utf-8

module TTY
  class Table
    # A class that represents table border options
    #
    # Used internally by {Table::Border} to manage options such as style
    #
    # @api private
    class BorderOptions < Struct.new(:characters, :separator, :style)
      # Initialize a BorderOptions
      #
      # @api public
      def initialize(*args)
        super(*args)
        self.characters = {} unless characters
      end

      # Create options instance from hash
      #
      # @api public
      def self.from(value)
        value ? new.update(value) : new
      end

      # Set all accessors with hash attributes
      #
      # @param [Hash, BorderOptions] obj
      #
      # @return [BorderOptions]
      #
      # @api public
      def update(obj)
        obj.each_pair do |key, value|
          send("#{key}=", value)
        end
        self
      end

      # Convert to hash
      #
      # @api public
      def to_hash
        hash = {}
        members.each do |key|
          value = send(key)
          hash[key.to_sym] = value if value
        end
        hash
      end
    end # BorderOptions
  end # Table
end # TTY

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
tty-table-0.10.0 lib/tty/table/border_options.rb
tty-table-0.9.0 lib/tty/table/border_options.rb
tty-table-0.8.0 lib/tty/table/border_options.rb
tty-table-0.7.0 lib/tty/table/border_options.rb
tty-table-0.6.0 lib/tty/table/border_options.rb
tty-table-0.5.0 lib/tty/table/border_options.rb
tty-table-0.4.0 lib/tty/table/border_options.rb
tty-table-0.3.0 lib/tty/table/border_options.rb
tty-table-0.2.0 lib/tty/table/border_options.rb
tty-table-0.1.0 lib/tty/table/border_options.rb
tty-0.1.2 lib/tty/table/border_options.rb
tty-0.1.1 lib/tty/table/border_options.rb
tty-0.1.0 lib/tty/table/border_options.rb