Sha256: 4dda96ff179ba58e11c2225423ffd71ba7bde32e18ecc0eceff1573af1777ae8

Contents?: true

Size: 1.07 KB

Versions: 38

Compression:

Stored size: 1.07 KB

Contents

# lib/gemwarrior/misc/hr.rb
# Standardized, cross-platform horizontal rule
# Cribbed extensively from https://github.com/ivantsepp/hr

require_relative '../game_options'

module Gemwarrior
  module Hr
    extend self

    def print(*patterns)
      Kernel.print string(*patterns)
    end

    def string(*patterns)
      options = patterns.last.is_a?(Hash) ? patterns.pop : {}
      screen_width = GameOptions.data['wrap_width']
      output = patterns.map do |pattern|
        pattern = pattern.to_s
        times = (screen_width / pattern.length) + 1
        (pattern * times)[0..screen_width - 1]
      end.join
      output << "\n"
      options = options.inject({}){|tmp,(k,v)| tmp[k.to_sym] = v.to_sym; tmp}
      options.any? ? output.colorize(options) : output
    end

    private

    def command_exists?(command)
      ENV['PATH'].split(File::PATH_SEPARATOR).any? { |path|
        (File.exist? File.join(path, "#{command}")) || (File.exist? File.join(path, "#{command}.com")) || (File.exist? File.join(path, "#{command}.exe"))
      }
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
gemwarrior-0.15.20 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.19 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.18 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.17 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.16 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.15 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.14 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.13 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.12 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.11 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.10 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.9 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.8 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.7 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.6 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.5 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.4 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.3 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.2 lib/gemwarrior/misc/hr.rb
gemwarrior-0.15.1 lib/gemwarrior/misc/hr.rb