branding 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84f12d04e4345b16255303cead54dd8dc0fc861b
4
- data.tar.gz: 0e29efd611b2ab5c9f16459a6312321b376566c2
3
+ metadata.gz: a6959beaee1359735390dd016cef33521c93f2df
4
+ data.tar.gz: f7c79a011689a917d6c3ff3917e829721027c512
5
5
  SHA512:
6
- metadata.gz: 8e1fb915ef2b0cdb5c7fa4b03056c3462112866c79ac02caa33e6fe43aaf18bb032c91514c03700c2bf80fc4ab5c4d851b50fd0066d729c5e1c6a75a036cb9fb
7
- data.tar.gz: 29d28dbacb70e62f3337250ca181f959c4a5286d9c3a7eab08407d8f583af8333f7b597a59ffc34a3ce97673fb862542ed0f332359e4f7fe24b38651596578bd
6
+ metadata.gz: baed7ed5ef481ad18fe6e13251682af9521286d0f34f64f0486ba91cd2a511eebe3501ce8a1916bd62d5025a412bf2f8f72ecc16723fb14987f03e230644ce81
7
+ data.tar.gz: aad0af2f3acbb30007ca9ab37542e35d2dbeb55f9d76430bfc9680a48b902af6cd44c14f5a6b2a978a48aa67382574e06cde2f79babadc0c33c99548f4eda140
@@ -1,2 +1,2 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.2
2
+ TargetRubyVersion: 2.0
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -8,5 +8,4 @@ require 'branding/version'
8
8
  require 'branding/railtie' if defined?(Rails)
9
9
 
10
10
  module Branding
11
-
12
11
  end
@@ -1,19 +1,19 @@
1
1
  module Branding
2
2
  module ANSI
3
- ATTRS = (0..8).map{|i| "\e[#{i}m".to_sym }.freeze
4
- FGCOLORS = (0..256).map{|i| "\e[38;5;#{i}m".to_sym }.freeze
5
- BGCOLORS = (0..256).map{|i| "\e[48;5;#{i}m".to_sym }.freeze
6
- #2580 - 259F
3
+ ATTRS = (0..8).map { |i| "\e[#{i}m".to_sym }.freeze
4
+ FGCOLORS = (0..256).map { |i| "\e[38;5;#{i}m".to_sym }.freeze
5
+ BGCOLORS = (0..256).map { |i| "\e[48;5;#{i}m".to_sym }.freeze
6
+ # 2580 - 259F
7
7
  SHADERS = [:"\u2591", :"\u2592", :"\u2593"].freeze
8
8
 
9
9
  module_function
10
10
 
11
- def fg(r,g,b)
12
- FGCOLORS[rgb_offset(r,g,b)]
11
+ def fg(r, g, b)
12
+ FGCOLORS[rgb_offset(r, g, b)]
13
13
  end
14
14
 
15
- def bg(r,g,b)
16
- BGCOLORS[rgb_offset(r,g,b)]
15
+ def bg(r, g, b)
16
+ BGCOLORS[rgb_offset(r, g, b)]
17
17
  end
18
18
 
19
19
  def reset
@@ -44,7 +44,7 @@ module Branding
44
44
  end
45
45
 
46
46
  # 0x10-0xE7: 6 × 6 × 6 = 216 colors
47
- def rgb_offset(r,g,b)
47
+ def rgb_offset(r, g, b)
48
48
  16 + (36 * scale_color(r)) + (6 * scale_color(g)) + scale_color(b)
49
49
  end
50
50
 
@@ -57,18 +57,18 @@ module Branding
57
57
 
58
58
  # we probably shouldn't be passing in non-ints
59
59
  def uint32_to_rgb(uint32)
60
- return [0,0,0] unless uint32.is_a?(Integer)
60
+ return [0, 0, 0] unless uint32.is_a?(Integer)
61
61
 
62
62
  r = (uint32 & 0xff000000) >> 24
63
63
  g = (uint32 & 0x00ff0000) >> 16
64
64
  b = (uint32 & 0x0000ff00) >> 8
65
65
 
66
- [r,g,b]
66
+ [r, g, b]
67
67
  end
68
68
 
69
69
  # we probably shouldn't be passing in non-ints
70
70
  def clamped(uint32)
71
- return [0,0,0] unless uint32.is_a?(Integer)
71
+ return [0, 0, 0] unless uint32.is_a?(Integer)
72
72
 
73
73
  r = (uint32 & 0xff000000) >> 24
74
74
  g = (uint32 & 0x00ff0000) >> 16
@@ -6,15 +6,15 @@ module Branding
6
6
 
7
7
  def self.terminal_size
8
8
  # TODO: make sure we can get this on linux
9
- begin
10
- `stty size`.split.map(&:to_i)
11
- rescue
12
- [40, 100]
13
- end
9
+
10
+ `stty size`.split.map(&:to_i)
11
+ rescue
12
+ [40, 100]
14
13
  end
15
14
 
16
- def initialize(width:, height:)
17
- @width, @height = width, height
15
+ def initialize(width: 0, height: 0)
16
+ @width = width
17
+ @height = height
18
18
  @rows, @cols = self.class.terminal_size
19
19
  @pixel_buffer = []
20
20
  end
@@ -38,13 +38,9 @@ module Branding
38
38
 
39
39
  def print
40
40
  @pixel_buffer.each_with_index do |pixel, idx|
41
- if (idx % width * pixel.width) >= cols
42
- next
43
- end
41
+ next if (idx % width * pixel.width) >= cols
44
42
 
45
- if idx % max_width == 0
46
- STDOUT.puts(ANSI.reset)
47
- end
43
+ STDOUT.puts(ANSI.reset) if idx % max_width == 0
48
44
 
49
45
  STDOUT.print(pixel)
50
46
  end
@@ -29,7 +29,7 @@ module Branding
29
29
 
30
30
  def run
31
31
  logo = Branding::Logo.new(@options.file)
32
- logo.algo = @options.algo
32
+ logo.algo = @options.algo if @options.algo
33
33
  logo.print
34
34
  end
35
35
  end
@@ -6,7 +6,7 @@ module Branding
6
6
  #
7
7
  #
8
8
  class Pixel
9
- def self.load_strategy(pixels, height:, width:)
9
+ def self.load_strategy(pixels, height: 0, width: 0)
10
10
  pixels.each do |pixel_value|
11
11
  yield self.new(pixel_value)
12
12
  end
@@ -99,7 +99,7 @@ module Branding
99
99
 
100
100
  class Pixel2x < Pixel
101
101
 
102
- def self.load_strategy(pixels, height:, width:)
102
+ def self.load_strategy(pixels, height: 0, width: 0)
103
103
  matrix = Matrix.build(height, width) do |row, col|
104
104
  pixels[col + row*width]
105
105
  end
@@ -14,7 +14,7 @@ module Branding
14
14
  class Imagedata
15
15
  include Enumerable
16
16
 
17
- def initialize(data:, scanline_width:, color_channels: )
17
+ def initialize(data: nil, scanline_width: 0, color_channels: 3)
18
18
  @scanline_width = scanline_width
19
19
  @color_channels = color_channels
20
20
 
@@ -33,7 +33,9 @@ module Branding
33
33
  end
34
34
 
35
35
  def each_scanline
36
- bytes_in_scanline = @scanline_width * @color_channels + 1 #the number of bytes is +1 because of the filter byte
36
+ # the number of bytes is + 1 because of the filter byte
37
+ bytes_in_scanline = @scanline_width * @color_channels + 1
38
+
37
39
  previous_scanline = nil
38
40
 
39
41
  each_slice(bytes_in_scanline) do |scanline|
@@ -133,10 +135,10 @@ module Branding
133
135
 
134
136
  # https://www.w3.org/TR/PNG/#9Filter-type-4-Paeth
135
137
  def paeth(x)
136
- x + paeth_predictor(a,b,c)
138
+ x + paeth_predictor(a, b, c)
137
139
  end
138
140
 
139
- def paeth_predictor(a,b,c)
141
+ def paeth_predictor(a, b, c)
140
142
  p = a + b - c
141
143
  pa = (p - a).abs
142
144
  pb = (p - b).abs
@@ -1,6 +1,5 @@
1
1
  module Branding
2
2
  class Railtie < Rails::Railtie
3
-
4
3
  unless Rails.env.production?
5
4
  initializer('branding.print_logo') do
6
5
  begin
@@ -1,3 +1,3 @@
1
1
  module Branding
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: branding
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Natchev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 2.4.5.1
135
+ rubygems_version: 2.6.4
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: Print your logo to the terminal.