bruce-banner 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ # YARD artifacts
20
+ .yardoc
21
+ _yardoc
22
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bruce-banner.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 bjh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,108 @@
1
+ bruce-banner
2
+ # BruceBanner
3
+
4
+ I am a lazy b****
5
+ I debug old school quite a lot and usually end up typing this pattern over and over:
6
+ ```ruby
7
+ puts '*' * 40
8
+ puts "thing: #{thing}"
9
+ ```
10
+
11
+ Since my laziness knows no bounds I created this so I can do this instead:
12
+
13
+ ```ruby
14
+ bb thing
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ in irb:
20
+
21
+ ```ruby
22
+ require 'bruce-banner'
23
+
24
+ # NOTE: if sticking a Hash directly in the call you may need the parens
25
+ bb({one:1, two:2})
26
+
27
+ # output with the default settings
28
+ ------------------
29
+ {:one=>1, :two=>2}
30
+ ```
31
+
32
+ Even better magic shamelessy stolen from Jim Weirich.
33
+ You pass a block with the name of a variable and it will print the name and the value.
34
+
35
+ ```ruby
36
+ magic = "this is voodoo magic!"
37
+ bb {:magic}
38
+
39
+ # outputs
40
+ ----------------------------
41
+ magic: this is voodoo magic!
42
+
43
+ # NOTE: passing the block overrides any passed in value but will pick up defaults
44
+ bb(magic, after:true) {:magic}
45
+
46
+ # outputs
47
+ ----------------------------
48
+ magic: this is voodoo magic!
49
+ ----------------------------
50
+ ```
51
+
52
+ ## Configuration Options
53
+
54
+ `:count` set the size of the banner string. Will be overridden if `size_to_fit` is true.
55
+ `:string` set the string to be repeated as the banner. Default is `'-'`
56
+ `:before` print the banner string before the payload? Defaults is `true`
57
+ `:after` print the banner string after the payload? Defaults is `false`
58
+ `:size_to_fit` counts the size of the payload string and uses that value as the banner size. Default is `true`. Will override `count` if set to `true`.
59
+
60
+ ```ruby
61
+ BruceBanner.configuration do |defaults_hash|
62
+ defaults_hash[:count] = 60
63
+ defaults_hash[:size_to_fit] = false
64
+ end
65
+ ```
66
+
67
+ You can also override the defaults on a per call basis:
68
+
69
+ ```ruby
70
+ bb({one:1, two:2}, after:true, string:'*')
71
+
72
+ # outputs
73
+ ******************
74
+ {:one=>1, :two=>2}
75
+ ******************
76
+ ```
77
+
78
+ ## And just for fun!
79
+
80
+ ```ruby
81
+ BruceBanner.make_him_angry!
82
+ ```
83
+
84
+ ## Installation
85
+
86
+ Add this line to your application's Gemfile:
87
+
88
+ gem 'bruce-banner'
89
+
90
+ And then execute:
91
+
92
+ $ bundle
93
+
94
+ Or install it yourself as:
95
+
96
+ $ gem install bruce-banner
97
+
98
+
99
+ ## TODO
100
+
101
+ make the output string more configurable, possibly allow creation of a message template.
102
+ i.e.
103
+ ```ruby
104
+ BruceBanner.template = "%s: %s"
105
+ bb("thing", 1432) #=> thing: 1432
106
+ ```
107
+
108
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bruce-banner/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bruce-banner"
8
+ gem.version = BruceBanner::VERSION
9
+ gem.authors = ["bjh"]
10
+ gem.email = ["bjh@fake.fake"]
11
+ gem.description = %q{wraps `puts' output with a banner}
12
+ gem.summary = %q{gem summary: I am a lazy bitch...hence the birth of this gem.}
13
+ gem.homepage = "https://github.com/bjh/bruce-banner"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,3 @@
1
+ module BruceBanner
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,94 @@
1
+ require "bruce-banner/version"
2
+
3
+ module BruceBanner
4
+
5
+ def self.make_him_angry!
6
+ # ASCII art from http://www.oocities.org/joan_stark/hulk.txt
7
+ output = []
8
+ output << " ,#####, "
9
+ output << " #_ _# "
10
+ output << " |e` `e| "
11
+ output << " | u | "
12
+ output << " \\ = / "
13
+ output << " |\\___/| "
14
+ output << " ___ ____/: :\\____ ___ "
15
+ output << " .' `.-===-\\ /-===-.` '. "
16
+ output << ' / .-"""""-.-"""""-. \ '
17
+ output << " /' =:= '\\ "
18
+ output << " .' ' .: o -=:=- o :. ' `. "
19
+ output << " (.' /'. '-.....-'-.....-' .'\\ '.) "
20
+ output << " /' ._/ \". : .\" \\_. '\\ "
21
+ output << " | .'| \". ---:--- .\" |'. | "
22
+ output << " | : | | ---:--- | | : | "
23
+ output << " \\ : | |_____:_____| | : / "
24
+ output << " / ( |----|------| ) \\ "
25
+ output << " /... .| /` | '\\ |. ...\\ "
26
+ output << "|::::/'' / .L__. \\ ''\\::::| "
27
+ output << " \"\"\"\" / / \\ \\ \"\"\"\" "
28
+ output << " : / \\ : "
29
+ output << " | / \\ | "
30
+ output << " \\ / \\ / "
31
+ output << " ) | | ( "
32
+ output << " / | | \\ "
33
+ output << " (/\\/\\| |/\\/\\) "
34
+ output << " \\ | | / "
35
+ output << " ) | | ( "
36
+ output << " _.-'` \\ / `'-._ "
37
+ output << " :________/ \\________; "
38
+ output << ""
39
+ output << "ASCII art from http://www.oocities.org/joan_stark/hulk.txt"
40
+
41
+ puts output.join "\n"
42
+ end
43
+
44
+ module Configuration
45
+ attr_accessor :defaults
46
+ end
47
+
48
+
49
+ # this is where the magic happens...
50
+ module ::Kernel
51
+ # block magic shamelessly stolen from Jim Weirich (with a small tweak)
52
+ # http://www.justskins.com/forums/print-out-a-variables-101209.html
53
+ def bb(what="", options={}, &block)
54
+ options = BruceBanner.defaults.merge(options)
55
+
56
+ if block_given?
57
+ name = block.call.to_s
58
+ what = "#{name}: #{eval(name, block.binding)}"
59
+ end
60
+
61
+ if options[:size_to_fit]
62
+ options[:count] = what.to_s.size
63
+ end
64
+
65
+ puts(options[:string] * options[:count]) if options[:before]
66
+ puts "#{what}"
67
+ puts(options[:string] * options[:count]) if options[:after]
68
+ end
69
+
70
+
71
+ # def debug(&block)
72
+ # name = block.call.to_s
73
+ # bb "#{name} = #{eval(name, block.binding)}"
74
+ # end
75
+ end
76
+
77
+ # configure-ater-iter-voodoo
78
+ def self.configuration
79
+ yield(self.defaults) if block_given?
80
+ end
81
+
82
+ extend Configuration
83
+
84
+ # Hulk SMASH!
85
+ attr_accessor :defaults
86
+
87
+ self.defaults = {
88
+ count:40,
89
+ string:'-',
90
+ before:true,
91
+ after:false,
92
+ size_to_fit:true
93
+ }
94
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bruce-banner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - bjh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: wraps `puts' output with a banner
15
+ email:
16
+ - bjh@fake.fake
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - bruce-banner.gemspec
27
+ - lib/bruce-banner.rb
28
+ - lib/bruce-banner/version.rb
29
+ homepage: https://github.com/bjh/bruce-banner
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.25
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: ! 'gem summary: I am a lazy bitch...hence the birth of this gem.'
53
+ test_files: []