the_great_escape 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/the_great_escape/escaper.rb +11 -0
- data/lib/the_great_escape/version.rb +3 -0
- data/lib/the_great_escape.rb +5 -0
- data/the_great_escape.gemspec +25 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a0943d518495527937a0ef408fc8e6a04ceb421
|
4
|
+
data.tar.gz: 4cf7908c808f16455bb0133148e96103c2ffb5db
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7871d5212d6cb67f6f9d3495e01f7eb508fce0baeafac607133c09328c1c0fe5eb9803bf384ecf810fcf8c38fc980c0558a4f34359150cf587c4576c873d5597
|
7
|
+
data.tar.gz: 8c207b8d6baafffc6e0e1e19af890dcc4795437cde7390fb5b7341a1413cf13b8fbe16ccb059e24380fc9d8a2e7e03cd960ab552c1ad4e1643d7e15985a81c62
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# TheGreatEscape
|
2
|
+
My first gem, the great escape. Seeing if your string contains SGR or other ASCII codes can be tricky, as when you print them to the screen they change the color/formatting of your terminal whether you want them to our not! Dumping results in more characters you have to either escape or sift through by eye. All the_great_escape does is escape strings that contain special sequences such as SGR parameters.
|
3
|
+
|
4
|
+
# Installation
|
5
|
+
1. Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'the_great_escape'
|
9
|
+
```
|
10
|
+
|
11
|
+
1. cd into your project's root:
|
12
|
+
```
|
13
|
+
$ cd my_project
|
14
|
+
```
|
15
|
+
1. execute:
|
16
|
+
```
|
17
|
+
$ bundle install
|
18
|
+
```
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
1. Require the_great_escape at the top of the file
|
22
|
+
```ruby
|
23
|
+
require 'the_great_escape'
|
24
|
+
```
|
25
|
+
|
26
|
+
1. And now use!
|
27
|
+
```ruby
|
28
|
+
require 'the_great_escape'
|
29
|
+
|
30
|
+
string = "hell \e[31mworld"
|
31
|
+
puts string # prints hell world to your screen. But everything is now in red! All you wanted to do was test your string contained an SGR code and now your terminal has been possessed!
|
32
|
+
puts string.dump # prints "hell \e[31mworld", complete with quotations. This can be confusing for newbies who are trying to write Regexes for strings containing SGR codes (such as myself)
|
33
|
+
|
34
|
+
escape_puts string # prints hell \e[31mworld Nice. Now you can see why your regex isn't working :P
|
35
|
+
|
36
|
+
# Using TheGreatEscape's escape method over dump does have a distinct advantage. It doesn't invalidate your code:
|
37
|
+
original_string = "hell \e[31m"
|
38
|
+
|
39
|
+
string = original_string.dump
|
40
|
+
puts string # prints "hell \\e[31m"
|
41
|
+
puts string.scan /\\e\[\d+m$/ # [] scan returns an empty array because string ends in a " not an m thanks to the in-place dump
|
42
|
+
|
43
|
+
string = escape original_string
|
44
|
+
puts string # prints hell \\e[31m which is easier to read
|
45
|
+
puts string.scan /\\e\[\d+m$/ # ["\\e[31m"] scan returns the SGR code at the end of string because string still ends in an m, despite the in-place escape
|
46
|
+
##
|
47
|
+
puts "\e[0" # reset your terminal to its default style if you run this code.
|
48
|
+
```
|
49
|
+
## Methods:
|
50
|
+
Method | Arguments | Example Usage | Description
|
51
|
+
------- | ----------- | ------------ | -
|
52
|
+
escape | string | escaped = escape "hell \e[31m" |escapes the string passed to it so it can be safely printed later. Does not invalidate the string
|
53
|
+
escape_puts | string | escape_putis "hell \e[31m" | escapes the string passed to it and prints it immediately to the console
|
54
|
+
|
55
|
+
# Contributing
|
56
|
+
Okay, I'm pretty new to Ruby and utterly new to git so I've created this to learn about string escapement, git collaboration and how to package, release and install gems. Regardless, to contribute:
|
57
|
+
|
58
|
+
1. Fork it ( https://github.com/[my-github-username]/the_great_escape/fork )
|
59
|
+
1. Create your feature branch (`git checkout -b my_new_feature`)
|
60
|
+
1. Commit your changes (`git commit -am 'Add my_new_feature'`)
|
61
|
+
1. Push to the branch (`git push origin my_new_feature`)
|
62
|
+
1. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "the_great_escape"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'the_great_escape/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "the_great_escape"
|
8
|
+
spec.version = TheGreatEscape::VERSION
|
9
|
+
spec.authors = ["jaytarka"]
|
10
|
+
spec.email = ["jaytarka@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Prints escaped strings to console'
|
13
|
+
spec.description = 'Escape strings with the Object#escape method. This escapes them so they can printed safely but they are not invalidated. Escape and print strings with one method with Object#escape_puts'
|
14
|
+
spec.homepage = 'https://github.com/jaytarka/the_great_escape'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: the_great_escape
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jaytarka
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Escape strings with the Object#escape method. This escapes them so they
|
56
|
+
can printed safely but they are not invalidated. Escape and print strings with one
|
57
|
+
method with Object#escape_puts
|
58
|
+
email:
|
59
|
+
- jaytarka@hotmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/the_great_escape.rb
|
73
|
+
- lib/the_great_escape/escaper.rb
|
74
|
+
- lib/the_great_escape/version.rb
|
75
|
+
- the_great_escape.gemspec
|
76
|
+
homepage: https://github.com/jaytarka/the_great_escape
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.6
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Prints escaped strings to console
|
100
|
+
test_files: []
|