nyan-cat 0.0.0 → 0.0.1

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ODRlMWFiM2RiZjNiNWQxZjBmNWYyNTRjMDYyZjNkMDMyNGFjYmZhZQ==
5
- data.tar.gz: !binary |-
6
- ODU5Y2JkMjk5NWYxOWVhMDY4MTA4ZTVjNTJmODcyZmZlODAzNGM2Zg==
2
+ SHA1:
3
+ metadata.gz: a185d33cda426522a2044e1d0dff777e48fd5d1f
4
+ data.tar.gz: ab268e381aaf3e0f41124a60ecb69c39afc4f081
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ZGE1ZjU4NmMyZGJiYTgwNzczMWI2NjA1YjZhMWEwY2Q4MDFhMGIwMDRiMjlk
10
- ZTMwMmYxZDQ0ZDJjMzNiNTI2MGU5MzM1OTJiYmUwZTgzYzQ3Zjk0YzQzMTE4
11
- ZTljNjIyYTU4ZDA4OTI3MGM5ZTY1ZWI2Y2ZmNWUwZTUwZTM3ZGM=
12
- data.tar.gz: !binary |-
13
- NjhkYWM2MmUzNzIwMTkzZWY3MDAzYWFmNTRiNTI2ZDYzMDI3ZTBjOTg4MTEz
14
- MGMzY2ZiMTIwNTg4MTdkOWI0NDljN2I3ZDA5MzA0NmY3M2MwZDZkZGNiMGQy
15
- NWJlNTk1ZTVmNzc2OWMzMjUyYTUxZjZlMTc4OGFjYzM1OTdlYzQ=
6
+ metadata.gz: 7bccabc1da8380955a78414ca02fc00cb4dc70ff3b6dc82410051999afd0888e037b358e360a3be94f92f408ee727faea422ba1a3f30df5a8760711af41547c4
7
+ data.tar.gz: 4ae9ae962dfbc72341845bbb7e90f88be2894386164929716a5dc9a0fd61683e6fae1bb28696026a90b6304fcb2fc98e7da437e129bf8e38655bfb35df4eb7a6
data/bin/nyan-cat CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'nyan-cat'
4
4
 
5
- NyanCat.new.render
5
+ NyanCat::UI.new(NyanCat.new_cat(:trail_length => 20)).render
@@ -0,0 +1,56 @@
1
+ module NyanCat
2
+ FRAME1 = <<'END'
3
+ _,------,
4
+ -| /\_/\
5
+ ~|__( ^ .^)
6
+ -"" ""
7
+ END
8
+
9
+ FRAME2 = <<'END'
10
+ -,------,
11
+ _| /\_/\
12
+ ^|__( ^ .^)
13
+ _ "" ""
14
+ END
15
+
16
+ class Cat
17
+ def initialize(opts = {})
18
+ @frames = opts.fetch(:frames) { [FRAME1, FRAME2] }
19
+ @trail_length = opts.fetch(:trail_length) { 9 }
20
+ @frame_count = 0
21
+ end
22
+
23
+ def tick(frame_count = nil)
24
+ frame_count ||= @frame_count
25
+ increment_internal_frame_count
26
+ generate_cat(frame_count)
27
+ end
28
+
29
+ private
30
+
31
+ def increment_internal_frame_count
32
+ @frame_count += 1
33
+ end
34
+
35
+ def generate_cat(frame_count)
36
+ index = frame_count % @frames.count
37
+ frame = @frames[index]
38
+ frame_with_trail = add_trail_to_each_line(frame, index)
39
+ end
40
+
41
+ def add_trail_to_each_line(frame, index)
42
+ lines = frame.split(/\r?\n/)
43
+ frame_with_trails = lines.map.with_index do |line, i|
44
+ @trail_length.times do |j|
45
+ line.prepend(trail_char(index, i, j))
46
+ end
47
+ line
48
+ end
49
+ frame_with_trails.join("\n")
50
+ end
51
+
52
+ def trail_char(frame_index, line_index, trail_index)
53
+ ((frame_index + line_index + trail_index) % 2).zero? ? '-' : '_'
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,29 @@
1
+ module NyanCat
2
+ class UI
3
+ def initialize(cat)
4
+ @cat = cat
5
+ end
6
+
7
+ def render
8
+ loop do
9
+ render_frame(@cat.tick)
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def render_frame(frame)
16
+ clear_screen
17
+ puts frame
18
+ delay_next_render
19
+ end
20
+
21
+ def delay_next_render
22
+ sleep (1.0/8.0)
23
+ end
24
+
25
+ def clear_screen
26
+ puts "\e[H\e[2J"
27
+ end
28
+ end
29
+ end
data/lib/nyan_cat.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'nyan-cat/cat.rb'
2
+ require 'nyan-cat/ui.rb'
3
+
4
+ module NyanCat
5
+ def self.new_cat(*args)
6
+ Cat.new(*args)
7
+ end
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nyan-cat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Keathley
@@ -17,9 +17,11 @@ executables:
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - lib/nyan-cat.rb
20
+ - lib/nyan_cat.rb
21
+ - lib/nyan-cat/cat.rb
22
+ - lib/nyan-cat/ui.rb
21
23
  - bin/nyan-cat
22
- homepage: http://rubygems.org/gems/hola
24
+ homepage: https://github.com/spyc3r/nyan-cat
23
25
  licenses:
24
26
  - MIT
25
27
  metadata: {}
@@ -29,17 +31,17 @@ require_paths:
29
31
  - lib
30
32
  required_ruby_version: !ruby/object:Gem::Requirement
31
33
  requirements:
32
- - - ! '>='
34
+ - - '>='
33
35
  - !ruby/object:Gem::Version
34
36
  version: '0'
35
37
  required_rubygems_version: !ruby/object:Gem::Requirement
36
38
  requirements:
37
- - - ! '>='
39
+ - - '>='
38
40
  - !ruby/object:Gem::Version
39
41
  version: '0'
40
42
  requirements: []
41
43
  rubyforge_project:
42
- rubygems_version: 2.1.5
44
+ rubygems_version: 2.1.8
43
45
  signing_key:
44
46
  specification_version: 4
45
47
  summary: Command line cat
data/lib/nyan-cat.rb DELETED
@@ -1,44 +0,0 @@
1
- class NyanCat
2
-
3
- FRAME1 = <<'END'
4
- -_-_-_-_-_-_-_,------,
5
- _-_-_-_-_-_-_-| /\_/\
6
- -_-_-_-_-_-_-~|__( ^ .^)
7
- _-_-_-_-_-_-_-"" ""
8
- END
9
-
10
- FRAME2 = <<'END'
11
- _-_-_-_-_-_-_-,------,
12
- -_-_-_-_-_-_-_| /\_/\
13
- _-_-_-_-_-_-_^|__( ^ .^)
14
- -_-_-_-_-_-_-_ "" ""
15
- END
16
-
17
- def render
18
- loop do
19
- frames.each do |frame|
20
- render_frame(frame)
21
- end
22
- end
23
- end
24
-
25
- private
26
-
27
- def frames
28
- [FRAME1, FRAME2]
29
- end
30
-
31
- def render_frame(frame)
32
- clear_screen
33
- puts frame
34
- delay_next_render
35
- end
36
-
37
- def delay_next_render
38
- sleep (1.0/8.0)
39
- end
40
-
41
- def clear_screen
42
- puts "\e[H\e[2J"
43
- end
44
- end