Module: TTM::HR

Defined in:
lib/tatum.rb

Overview

Handles building horizontal rules.

Class Method Summary collapse

Class Method Details

.parse_opts(opts = nil) ⇒ Object

Parses the options sent to .puts



689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
# File 'lib/tatum.rb', line 689

def self.parse_opts(opts=nil)
  # default
  default = {'dash'=>'-'}
  
  # nil
  if opts.nil?
    return default
  end
  
  # if opts is not a hash, use that object as the title
  if not opts.is_a?(Hash)
    opts = {'title'=>opts.to_s}
  end
  
  # merge into default
  opts = default.merge(opts)
  
  # return
  return opts
end

.puts(opts = nil, &block) ⇒ Object

Builds and outputs a horizontal rule. See TTM.hr for details.



650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
# File 'lib/tatum.rb', line 650

def self.puts(opts=nil, &block)
  opts = parse_opts(opts)
  dash = opts['dash']
  
  # output with title or plain
  if opts['title']
    out = dash * 3
    out += ' '
    out += opts['title']
    out += ' '
    out += dash * (TTM.hr_width - out.length)
    TTM.puts out
  else
    TTM.puts dash * TTM.hr_width
  end
  
  # if block given, yield and output another hr
  if block_given?
    begin
      yield
    ensure
      TTM.puts dash * TTM.hr_width
    end
  end
  
  # always return nil
  return nil
end