Sha256: f8a45bc60593946e4d957f005a67e9e950b48abaef02d34b972601e682bdec1d

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# -*- encoding: utf-8 -*-

module TTY
  class Table

    # A class that represents table border options
    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|
          self.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

4 entries across 4 versions & 1 rubygems

Version Path
tty-0.0.11 lib/tty/table/border_options.rb
tty-0.0.10 lib/tty/table/border_options.rb
tty-0.0.9 lib/tty/table/border_options.rb
tty-0.0.8 lib/tty/table/border_options.rb