vamp 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,81 @@
1
+ module Vamp
2
+ # play animation on console
3
+ class Animator
4
+ attr_accessor :data
5
+ attr_accessor :number
6
+
7
+ def initialize(file, number = 31)
8
+ @data = []
9
+ @number = number
10
+ lines = IO.readlines(file)
11
+ lines.each_slice(number) do |block|
12
+ d = []
13
+ block.each do |line|
14
+ # puts line.class
15
+ # puts printf("%-40s", line)
16
+ # d << line
17
+ d << (line.rstrip + (" " * 80))[0..80]
18
+ # d << sprintf("%80s", line)
19
+ # puts block.length
20
+ end
21
+ # puts lines
22
+ @data << d
23
+ end
24
+ end
25
+
26
+ def clear
27
+ print "\e[H\e[2J"
28
+ end
29
+
30
+ def home
31
+ print "\e[H\e[#{number}F"
32
+ end
33
+
34
+ def home
35
+ print "\e[H\e[#{number}F"
36
+ end
37
+
38
+ def down
39
+ # number.times { puts }
40
+ print "\e[H\e[#{number}E"
41
+ end
42
+
43
+ def flush
44
+ $stdout.flush
45
+ end
46
+
47
+ def animate(msg)
48
+ home
49
+ print msg
50
+ flush
51
+ sleep(1.0/48.0)
52
+ end
53
+
54
+ def cursor_off
55
+ print "\e[H\e[?25l"
56
+ end
57
+
58
+ def cursor_on
59
+ print "\e[H\e[?25h"
60
+ end
61
+
62
+ def play
63
+ if $stdout.isatty
64
+ begin
65
+ cursor_off
66
+ clear
67
+ data.each { |lines| animate(lines.join("\n"))}
68
+ ensure
69
+ cursor_on
70
+ down
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ if __FILE__ == $0
78
+ # get root directory of this gem
79
+ animator = Vamp::Animator.new(File.join(Gem.loaded_specs["vamp"].gem_dir, "files", "pyramid.txt"))
80
+ animator.play
81
+ end
data/lib/vamp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Vamp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/vamp.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require "vamp/version"
2
+ require "vamp/animator"
2
3
 
3
4
  module Vamp
5
+
6
+ # ascii art vampire by the queen of ascii art: Joan Stark
7
+ # https://en.wikipedia.org/wiki/Joan_Stark
4
8
  VAMPIRE = <<-END
5
9
  =/\\ /\\=
6
10
  / \\'._ (\\_/) _.'/ \\
@@ -11,6 +15,7 @@ module Vamp
11
15
  ` " " `
12
16
  END
13
17
 
18
+ # return random quote
14
19
  def quote
15
20
  [
16
21
  "Twilight, again. Another ending. No matter how perfect the day is, it always has to end.",
@@ -49,7 +54,15 @@ module Vamp
49
54
  "There is a good reason why these rules were created, and they are the only reason we have survived this long!",
50
55
  "First rule about vampires, don`t believe anything you read.",
51
56
  "Stupid, unreliable vampire.",
52
- "Which is tempting you more, my blood or my body?"
57
+ "Which is tempting you more, my blood or my body?",
58
+ "You can have my soul. I don't want it without you - it's yours already!",
59
+ "It appears we have a lot to learn about each other.",
60
+ "You have nothing to worry about. You are completely safe here.",
61
+ "One thing vampire children are taught is, never run with a wooden stake.",
62
+ "The unknown is now my reality, for I do not yet understand what I have become." \
63
+ " The future brings so many questions, so many fears. But the first step, the first day, has arrived.",
64
+ "Please forgive me, but I desperately need your guidance. I apologise for breaking the Chain and awakening you " \
65
+ " a head of schedule, but I fear we may all be in grave danger."
53
66
  ].sample
54
67
  end
55
68
  end
data/sample/cli.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "thor"
2
+ require "vamp"
3
+
4
+ class CLI < Thor
5
+ include Vamp
6
+
7
+ def initialize(*args)
8
+ at_exit { thats_all_folks }
9
+ super
10
+ end
11
+
12
+ desc "example", "an example task"
13
+ def example
14
+ puts "I'm a thor task!"
15
+ end
16
+
17
+ private
18
+
19
+ def thats_all_folks
20
+ say
21
+ say VAMPIRE, :yellow
22
+ say
23
+ say " \"#{quote}\"", :blue
24
+ say
25
+ end
26
+ end
27
+
28
+ CLI.start(ARGV)
data/spec/vamp_spec.rb CHANGED
@@ -17,17 +17,11 @@ describe Vamp do
17
17
  expect(quote.length).to be_between(11, 999)
18
18
  end
19
19
 
20
- subject(:messages) do
21
- messages = Set.new
22
- maximum = 10
23
- minimum = maximum / 1
24
- end
25
20
  it "gives different quotes" do
26
21
  messages = Set.new
27
22
  maximum = 10
28
- minimum = maximum / 1
23
+ minimum = maximum / 2
29
24
  maximum.times { messages << quote }
30
- let()
31
25
  begin
32
26
  expect(messages.size).to be_between(minimum, maximum)
33
27
  rescue
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Meyling
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-13 00:00:00.000000000 Z
11
+ date: 2015-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -51,8 +51,11 @@ files:
51
51
  - LICENSE.txt
52
52
  - README.md
53
53
  - Rakefile
54
+ - files/pyramid.txt
54
55
  - lib/vamp.rb
56
+ - lib/vamp/animator.rb
55
57
  - lib/vamp/version.rb
58
+ - sample/cli.rb
56
59
  - spec/spec_helper.rb
57
60
  - spec/vamp_spec.rb
58
61
  - vamp.gemspec