vedeu 0.1.10 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu.rb +2 -10
  3. data/lib/vedeu/api/api.rb +29 -1
  4. data/lib/vedeu/api/events.rb +1 -26
  5. data/lib/vedeu/api/{base.rb → helpers.rb} +1 -18
  6. data/lib/vedeu/api/interface.rb +16 -3
  7. data/lib/vedeu/api/line.rb +29 -4
  8. data/lib/vedeu/api/log.rb +13 -1
  9. data/lib/vedeu/api/store.rb +0 -4
  10. data/lib/vedeu/api/stream.rb +29 -2
  11. data/lib/vedeu/api/view.rb +4 -2
  12. data/lib/vedeu/models/attributes/attributes.rb +25 -0
  13. data/lib/vedeu/models/attributes/colour_translator.rb +0 -10
  14. data/lib/vedeu/models/colour.rb +23 -3
  15. data/lib/vedeu/models/composition.rb +32 -2
  16. data/lib/vedeu/models/geometry.rb +38 -22
  17. data/lib/vedeu/models/interface.rb +57 -12
  18. data/lib/vedeu/models/line.rb +28 -4
  19. data/lib/vedeu/models/stream.rb +36 -6
  20. data/lib/vedeu/output/buffers.rb +8 -4
  21. data/lib/vedeu/output/clear.rb +1 -3
  22. data/lib/vedeu/output/render.rb +12 -4
  23. data/lib/vedeu/support/esc.rb +12 -2
  24. data/lib/vedeu/support/menu.rb +10 -10
  25. data/test/lib/vedeu/api/events_test.rb +4 -4
  26. data/test/lib/vedeu/api/interface_test.rb +9 -9
  27. data/test/lib/vedeu/api/view_test.rb +1 -1
  28. data/test/lib/vedeu/models/attributes/{collection_test.rb → attributes_test.rb} +7 -7
  29. data/test/lib/vedeu/models/geometry_test.rb +0 -65
  30. data/test/lib/vedeu/models/line_test.rb +29 -4
  31. data/test/lib/vedeu/models/stream_test.rb +56 -11
  32. data/test/lib/vedeu/output/render_test.rb +1 -0
  33. data/vedeu.gemspec +1 -3
  34. metadata +6 -38
  35. data/lib/vedeu/models/attributes/background.rb +0 -7
  36. data/lib/vedeu/models/attributes/collection.rb +0 -11
  37. data/lib/vedeu/models/attributes/foreground.rb +0 -7
  38. data/lib/vedeu/models/attributes/interface_collection.rb +0 -13
  39. data/lib/vedeu/models/attributes/line_collection.rb +0 -9
  40. data/lib/vedeu/models/attributes/stream_collection.rb +0 -9
  41. data/lib/vedeu/models/style.rb +0 -15
  42. data/test/lib/vedeu/models/attributes/interface_collection_test.rb +0 -40
  43. data/test/lib/vedeu/models/attributes/line_collection_test.rb +0 -25
  44. data/test/lib/vedeu/models/attributes/stream_collection_test.rb +0 -23
  45. data/test/lib/vedeu/models/style_test.rb +0 -48
  46. data/test/support/bench.rb +0 -34
  47. data/test/support/colours.rb +0 -39
@@ -1,9 +0,0 @@
1
- module Vedeu
2
- class LineCollection < Virtus::Attribute
3
- include Collection
4
-
5
- def coerce(values)
6
- coercer(values, Line, :streams)
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Vedeu
2
- class StreamCollection < Virtus::Attribute
3
- include Collection
4
-
5
- def coerce(values)
6
- coercer(values, Stream, :text)
7
- end
8
- end
9
- end
@@ -1,15 +0,0 @@
1
- module Vedeu
2
- class Style < Virtus::Attribute
3
- def coerce(value_or_values)
4
- return '' if value_or_values.nil? || value_or_values.empty?
5
-
6
- if value_or_values.is_a?(::Array)
7
- value_or_values.map { |s| Esc.string(s) }.join
8
-
9
- else
10
- Esc.string(value_or_values)
11
-
12
- end
13
- end
14
- end
15
- end
@@ -1,40 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
- describe InterfaceCollection do
5
- describe '#coerce' do
6
- before { API::Store.reset }
7
-
8
- it 'returns an empty collection when there are no interfaces' do
9
- composition = Composition.new
10
- composition.interfaces.must_equal([])
11
- end
12
-
13
- it 'returns a collection when there is a single interface' do
14
- Vedeu.interface('dumb') {}
15
-
16
- composition = Composition.new(
17
- {
18
- interfaces: { name: 'dumb' }
19
- }
20
- )
21
- composition.interfaces.first.must_be_instance_of(Interface)
22
- end
23
-
24
- it 'returns a collection when there are multiple interfaces' do
25
- Vedeu.interface('dumb') {}
26
- Vedeu.interface('dumber') {}
27
-
28
- composition = Composition.new(
29
- {
30
- interfaces: [
31
- { name: 'dumb' },
32
- { name: 'dumber' }
33
- ]
34
- }
35
- )
36
- composition.interfaces.size.must_equal(2)
37
- end
38
- end
39
- end
40
- end
@@ -1,25 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
- describe LineCollection do
5
- let(:interface) { Interface.new(attributes) }
6
-
7
- describe '#coerce' do
8
- it 'returns an empty collection when there are no lines' do
9
- Interface.new({ lines: [] }).lines.must_equal([])
10
- end
11
-
12
- it 'contains a single Line object when there is a single line' do
13
- Interface.new({ lines: { streams: { text: 'some text' } } })
14
- .lines.size.must_equal(1)
15
- end
16
-
17
- it 'contains multiple Line objects when there are multiple lines' do
18
- Interface.new({ lines: [
19
- { text: 'some text' },
20
- { text: 'some more text' }
21
- ] }).lines.size.must_equal(2)
22
- end
23
- end
24
- end
25
- end
@@ -1,23 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
- describe StreamCollection do
5
- describe '#coerce' do
6
- it 'returns an empty array when there is no stream' do
7
- Line.new.streams.must_equal([])
8
- end
9
-
10
- it 'contains a single Stream when there is a single stream' do
11
- Line.new({ streams: [{ text: 'some text' }] }).streams.size
12
- .must_equal(1)
13
- end
14
-
15
- it 'contains multiple Stream when there are multiple streams' do
16
- Line.new({ streams: [
17
- { text: 'some text' },
18
- { text: 'some more text' }
19
- ] }).streams.size.must_equal(2)
20
- end
21
- end
22
- end
23
- end
@@ -1,48 +0,0 @@
1
- require 'test_helper'
2
-
3
- module Vedeu
4
- class TestStyle
5
- include Virtus.model
6
-
7
- attribute :style, Style
8
- end
9
-
10
- describe Style do
11
- describe '#style' do
12
- it 'returns an escape sequence for a single style' do
13
- model = TestStyle.new(style: 'normal')
14
- model.style.must_equal("\e[24m\e[21m\e[27m")
15
- end
16
-
17
- it 'returns an escape sequence for multiple styles' do
18
- model = TestStyle.new(style: ['normal', 'underline'])
19
- model.style.must_equal("\e[24m\e[21m\e[27m\e[4m")
20
- end
21
-
22
- it 'returns an empty string for an unknown style' do
23
- model = TestStyle.new(style: 'unknown')
24
- model.style.must_equal('')
25
- end
26
-
27
- it 'has a style attribute' do
28
- model = TestStyle.new(style: ['normal'])
29
- model.style.must_equal("\e[24m\e[21m\e[27m")
30
- end
31
-
32
- it 'returns an empty string for empty or nil' do
33
- model = TestStyle.new(style: '')
34
- model.style.must_equal('')
35
- end
36
-
37
- it 'returns an empty string for empty or nil' do
38
- model = TestStyle.new(style: nil)
39
- model.style.must_equal('')
40
- end
41
-
42
- it 'returns an empty string for empty or nil' do
43
- model = TestStyle.new(style: [])
44
- model.style.must_equal('')
45
- end
46
- end
47
- end
48
- end
@@ -1,34 +0,0 @@
1
- require 'benchmark'
2
-
3
- class Foo
4
- def bar(a, b)
5
- a + b
6
- end
7
-
8
- def baz
9
- a + b
10
- end
11
-
12
- def a
13
- rand(1000_000)
14
- end
15
-
16
- def b
17
- rand(1000_000)
18
- end
19
- end
20
-
21
- foo = Foo.new
22
-
23
- Benchmark.bm 30 do |x|
24
- x.report 'original method' do
25
- 1000000.times do |_|
26
- foo.bar(rand(1_000_000), rand(1_000_000))
27
- end
28
- end
29
- x.report 'shiny new method' do
30
- 1000000.times do |_|
31
- foo.baz
32
- end
33
- end
34
- end
@@ -1,39 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require_relative '../../lib/vedeu/models/attributes/colour_translator'
3
-
4
- values = ["00", "5f", "87", "af", "d7", "ff"]
5
- codes = {}
6
-
7
- values.each do |r|
8
- values.each do |g|
9
- values.each do |b|
10
- value = ["#", r, g, b].join
11
- trans = Vedeu::ColourTranslator.translate(value)
12
- codes[trans] = value
13
- end
14
- end
15
- end
16
-
17
- # basic
18
- 30.upto(38) do |fg|
19
- 40.upto(48) do |bg|
20
- print "\e[38;2;#{fg}m\e[48;2;#{bg}mVedeu\e[0m"
21
- end
22
- print "\n"
23
- end
24
-
25
- # foreground
26
- codes.each_slice(6) do |c|
27
- c.each do |k, v|
28
- printf "\e[48;2;49m \e[38;5;%s30m%s %3s ", k, v, k
29
- end
30
- print "\e[48;2;49m\e[38;2;39m\n"
31
- end
32
-
33
- # background
34
- codes.each_slice(6) do |c|
35
- c.each do |k, v|
36
- printf "\e[48;5;%sm \e[38;2;30m%s %3s ", k, v, k
37
- end
38
- print "\e[48;2;49m\e[38;2;39m\n"
39
- end