Sha256: 4dcf17a0ae3b963bf48f9701a4969eefe7cb67765153e0b83a378d9e15ac8634

Contents?: true

Size: 648 Bytes

Versions: 2

Compression:

Stored size: 648 Bytes

Contents

require 'optparse'

module LovelyRufus class CLIWrapper
  def initialize args = ARGV, text_wrapper: TextWrapper
    @settings     = Settings.new args
    @text_wrapper = text_wrapper
  end

  def run stream = $stdin
    puts text_wrapper.wrap stream.read, width: settings.width
  end

  attr_reader :settings, :text_wrapper
  private     :settings, :text_wrapper

  private

  class Settings
    attr_reader :width

    def initialize args
      @width = 72
      OptionParser.new do |opts|
        opts.on '-w', '--width WIDTH', Integer, 'Wrapping width' do |width|
          @width = width
        end
      end.parse! args
    end
  end
end end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lovely_rufus-0.1.1 lib/lovely_rufus/cli_wrapper.rb
lovely_rufus-0.1.0 lib/lovely_rufus/cli_wrapper.rb