lib/tty/table/border_options.rb in tty-table-0.11.0 vs lib/tty/table/border_options.rb in tty-table-0.12.0

- old
+ new

@@ -5,52 +5,57 @@ # 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 - + class BorderOptions # Create options instance from hash # # @api public - def self.from(value) - value ? new.update(value) : new + def self.from(options) + return new if options.nil? + + opts = case options + when self.class + options.to_hash + else + options + end + new(**opts) end - # Set all accessors with hash attributes + attr_accessor :characters + + attr_accessor :separator + + attr_accessor :style + + # Initialize a BorderOptions # - # @param [Hash, BorderOptions] obj + # @param [String] style + # the style like :red + # @param [String] separator + # the separator character + # @param [Hash] characters + # the border characters # - # @return [BorderOptions] - # # @api public - def update(obj) - obj.each_pair do |key, value| - send("#{key}=", value) - end - self + def initialize(characters: {}, separator: nil, style: nil) + @characters = characters + @separator = separator + @style = style end # Convert to hash # + # @return [Hash] + # # @api public def to_hash - hash = {} - members.each do |key| - value = send(key) - hash[key.to_sym] = value if value - end - hash + { characters: characters, separator: separator, style: style } end - # return true if there should be a separator AFTER this line + # Check if there should be a separator AFTER this line # # @param [Integer] line # # @return [Boolean] #