rainbow_printer 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 +8 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +19 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/demos/demo.png +0 -0
- data/lib/rainbow_printer.rb +52 -0
- data/lib/rainbow_printer/version.rb +3 -0
- data/rainbow_printer.gemspec +26 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 43c9693fd79f975f0c9ac09216c32974e85d23aa5ffc9c6dc2c8326ace40e8f7
|
4
|
+
data.tar.gz: af8147661784fd8a94735fd6d54d18526d53e12e0fade44551a187699c62293f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5d42bbfd44662d3406b5690f9541cdeb73af37d5247434e5bf0ea011a2e845642f6a2b84261a075c52066197ac46237eeffcf9aaf63d7f66abca26cc84662ed3
|
7
|
+
data.tar.gz: 75c6e32d28b364ae67b2cbc6367bf21a9d4f62de4c439c4c176fddead17fe57e4749867484ea8bff21560cdbf59fd3c2a18b00e23fc2bb755fd88eda6fe3a0e8
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# RainbowPrinter
|
2
|
+
|
3
|
+
Rainbow Printer, it adds some methods to help your output display look likes 7 colours of the rainbow 🌈
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rainbow_printer'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rainbow_printer
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Easy to print yout text or array with Rainbow Printer.
|
24
|
+
|
25
|
+
- For texts:
|
26
|
+
|
27
|
+
```
|
28
|
+
rainbow_printer "Hello World! I'm Rainbow Printer, I'll adds some methods to help your output display look likes 7 colours of the rainbow ;)"
|
29
|
+
```
|
30
|
+
|
31
|
+
- For Array:
|
32
|
+
|
33
|
+
```
|
34
|
+
rainbow_printer [1, true, "Rainbow Printer"]
|
35
|
+
```
|
36
|
+
Btw, you can use alias `rb_puts` instead of `rainbow_printer`.
|
37
|
+
|
38
|
+
Demo:
|
39
|
+
|
40
|
+

|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
|
+
|
46
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rainbow_printer.
|
51
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rainbow_printer"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/demos/demo.png
ADDED
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "rainbow_printer/version"
|
2
|
+
|
3
|
+
module RainbowPrinter
|
4
|
+
class Error < StandardError; end
|
5
|
+
|
6
|
+
class Core
|
7
|
+
PI_3 = Math::PI / 3
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@colors = (0...(6 * 7)).map do |n|
|
11
|
+
n *= 1.0 / 6
|
12
|
+
r = (3 * Math.sin(n) + 3).to_i
|
13
|
+
g = (3 * Math.sin(n + 2 * PI_3) + 3).to_i
|
14
|
+
b = (3 * Math.sin(n + 4 * PI_3) + 3).to_i
|
15
|
+
|
16
|
+
36 * r + 6 * g + b + 16
|
17
|
+
end
|
18
|
+
@color_index = 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def rainbow
|
22
|
+
@color_index == (@colors.size - 1) ? @color_index = 0 : @color_index += 1
|
23
|
+
@colors[@color_index]
|
24
|
+
end
|
25
|
+
|
26
|
+
def puts_with_rainbow(input)
|
27
|
+
output = ''
|
28
|
+
input.to_s.split('').each do |str|
|
29
|
+
output += "\e[38;5;#{rainbow}m#{str}\e[0m"
|
30
|
+
end
|
31
|
+
puts output
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.puts(input)
|
35
|
+
if input.is_a?(String)
|
36
|
+
RainbowPrinter::Core.new.puts_with_rainbow input
|
37
|
+
elsif input.is_a?(Array)
|
38
|
+
input.each do |child|
|
39
|
+
RainbowPrinter::Core.new.puts_with_rainbow child
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Adding rainbow_printer method, allow call in ruby code
|
47
|
+
def rainbow_printer(input)
|
48
|
+
RainbowPrinter::Core.puts input
|
49
|
+
end
|
50
|
+
|
51
|
+
# Alias for rainbow_printer
|
52
|
+
alias rb_puts rainbow_printer
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'lib/rainbow_printer/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "rainbow_printer"
|
5
|
+
spec.version = RainbowPrinter::VERSION
|
6
|
+
spec.authors = 'Derek Nguyen'
|
7
|
+
spec.email = 'derek.nguyen.269@gmail.com'
|
8
|
+
|
9
|
+
spec.summary = 'Rainbow Printer, it adds some methods to help your output display look likes 7 colours of the rainbow 🌈'
|
10
|
+
spec.description = 'Rainbow Printer, it adds some methods to help your output display look likes 7 colours of the rainbow 🌈'
|
11
|
+
spec.homepage = 'https://github.com/dereknguyen269/rainbow_printer'
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = 'https://github.com/dereknguyen269/rainbow_printer'
|
16
|
+
spec.metadata["changelog_uri"] = 'https://github.com/dereknguyen269/rainbow_printer'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rainbow_printer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Derek Nguyen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: "Rainbow Printer, it adds some methods to help your output display look
|
14
|
+
likes 7 colours of the rainbow \U0001F308"
|
15
|
+
email: derek.nguyen.269@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- bin/console
|
26
|
+
- bin/setup
|
27
|
+
- demos/demo.png
|
28
|
+
- lib/rainbow_printer.rb
|
29
|
+
- lib/rainbow_printer/version.rb
|
30
|
+
- rainbow_printer.gemspec
|
31
|
+
homepage: https://github.com/dereknguyen269/rainbow_printer
|
32
|
+
licenses: []
|
33
|
+
metadata:
|
34
|
+
homepage_uri: https://github.com/dereknguyen269/rainbow_printer
|
35
|
+
source_code_uri: https://github.com/dereknguyen269/rainbow_printer
|
36
|
+
changelog_uri: https://github.com/dereknguyen269/rainbow_printer
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.3.0
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubygems_version: 3.1.2
|
53
|
+
signing_key:
|
54
|
+
specification_version: 4
|
55
|
+
summary: "Rainbow Printer, it adds some methods to help your output display look likes
|
56
|
+
7 colours of the rainbow \U0001F308"
|
57
|
+
test_files: []
|