rasskey 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rasskey.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # RassKey: R(uby) ASCII library
2
+
3
+ RassKey provides a few simple ASCII helpers for Ruby. Since this is the first release, the current functionality is fairly limited:
4
+
5
+ * RassKey::Box
6
+ * String.to\_box helper
7
+
8
+ ## RassKey::Box
9
+
10
+ RassKey::Box is a pretty basic ASCII box creator. It was designed to draw a box around a string. The primary use case was simple ASCII Visio-style charts.
11
+
12
+ Currently RassKey accepts two options describing the box:
13
+
14
+ * padding
15
+ * glyph
16
+
17
+ These can either be set via an options hash passed to the _draw_ method or as setters:
18
+
19
+ >> require 'rasskey'
20
+ => true
21
+ >> mybox = RassKey::Box.new :padding => 10, :glyph => "#"
22
+ => #<RassKey::Box:0x7eff41e181f0 @padding=10, @glyph="#">
23
+ >> puts mybox.draw("This is a sample text")
24
+ ###########################################
25
+ # #
26
+ # #
27
+ # #
28
+ # #
29
+ # #
30
+ # This is a sample text #
31
+ # #
32
+ # #
33
+ # #
34
+ # #
35
+ # #
36
+ ###########################################
37
+ >> mybox.padding = 5
38
+ => 5
39
+ >> mybox.glyph = "*"
40
+ => "*"
41
+ >> puts mybox.draw("This is a sample text again")
42
+ ***************************************
43
+ * *
44
+ * *
45
+ * This is a sample text again *
46
+ * *
47
+ * *
48
+ ***************************************
49
+
50
+ ## String.to\_box
51
+
52
+ You can also use it as a String method:
53
+
54
+ >> require 'rasskey'
55
+ => true
56
+ >> mystr = "foobarbaz"
57
+ => "foobarbaz"
58
+ >> puts mystr.to_box
59
+ *************
60
+ * foobarbaz *
61
+ *************
62
+ => nil
63
+ >> puts mystr.to_box :padding => 12, :glyph => "%"
64
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
+ % %
66
+ % %
67
+ % %
68
+ % %
69
+ % %
70
+ % %
71
+ % foobarbaz %
72
+ % %
73
+ % %
74
+ % %
75
+ % %
76
+ % %
77
+ % %
78
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
+
80
+ # TODO
81
+
82
+ * Tests
83
+ * Get attr\_accessors working for String helper
84
+ * Get LICENSE headers and rdoc in place
85
+ * Work on allowing multi-char glyphs
86
+ * Word-wrapping for text
87
+ * Other "shapes"
88
+ * Custom elements (like say captions)
89
+ * Draw links between shapes
90
+ * Some type of canvas and auto-positioning
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,45 @@
1
+ module RassKey
2
+ class Box
3
+ class << self
4
+ attr_accessor :default_padding
5
+ attr_accessor :default_glyph
6
+
7
+ end
8
+
9
+ @default_padding = 1
10
+ @default_glyph = '*'
11
+
12
+ attr_accessor :padding
13
+ attr_accessor :glyph
14
+
15
+ def initialize(options = {})
16
+ options = {
17
+ :padding => RassKey::Box.default_padding,
18
+ :glyph => RassKey::Box.default_glyph
19
+ }.merge(options)
20
+
21
+ self.padding = options[:padding]
22
+ self.glyph = options[:glyph]
23
+
24
+ super()
25
+ end
26
+
27
+ def draw(data)
28
+ @glyph.length == 1 ? (@glyph = @glyph) : (@glyph = @glyph[0,1])
29
+ whitespace = " " * ( data.length + (@padding * 2) )
30
+ spacing = " " * @padding || " "
31
+ content_line = "#{@glyph}#{spacing}#{data}#{spacing}#{@glyph}"
32
+ top = @glyph * content_line.length
33
+ side = @glyph
34
+ bottom = @glyph * content_line.length
35
+ box = []
36
+ box << top
37
+ (@padding/2).times { box << "#{@glyph}#{whitespace}#{@glyph}" }
38
+ box << "#{content_line}"
39
+ (@padding/2).times { box << "#{@glyph}#{whitespace}#{@glyph}" }
40
+ box << bottom
41
+ box.join("\n")
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,18 @@
1
+ module RassKey #:nodoc:
2
+ module String #:nodoc:
3
+ def self.included(base)
4
+ base.class_eval do
5
+ attr_accessor :padding
6
+ attr_accessor :glyph
7
+ end
8
+ end
9
+
10
+ def to_box(options = {})
11
+ RassKey::Box.new(options).draw(self)
12
+ end
13
+ end
14
+ end
15
+
16
+ ::String.class_eval do
17
+ include RassKey::String
18
+ end
@@ -0,0 +1,3 @@
1
+ module Rasskey
2
+ VERSION = "0.0.2"
3
+ end
data/lib/rasskey.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'lib/rasskey/extensions/string'
2
+ require 'lib/rasskey/box'
data/rasskey.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rasskey/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rasskey"
7
+ s.version = Rasskey::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["lusis"]
10
+ s.email = ["lusis.org+rubygems.org@gmail.com"]
11
+ s.homepage = "http://github.com/lusis/rasskey"
12
+ s.summary = %q{Small Ruby Library for ASCII drawing}
13
+ s.description = %q{Small Ruby Library for ASCII drawing}
14
+
15
+ s.rubyforge_project = "rasskey"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rasskey
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - lusis
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-27 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Small Ruby Library for ASCII drawing
23
+ email:
24
+ - lusis.org+rubygems.org@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - README.md
35
+ - Rakefile
36
+ - lib/rasskey.rb
37
+ - lib/rasskey/box.rb
38
+ - lib/rasskey/extensions/string.rb
39
+ - lib/rasskey/version.rb
40
+ - rasskey.gemspec
41
+ has_rdoc: true
42
+ homepage: http://github.com/lusis/rasskey
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project: rasskey
71
+ rubygems_version: 1.3.7
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Small Ruby Library for ASCII drawing
75
+ test_files: []
76
+