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
@@ -5,7 +5,7 @@ module Vedeu
5
5
  describe View do
6
6
  before do
7
7
  Store.reset
8
- Interface.save('testing_view') do
8
+ Interface.create('testing_view') do
9
9
  x 1
10
10
  y 1
11
11
  colour foreground: '#ffffff', background: '#000000'
@@ -2,36 +2,36 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
  class TestClass
5
- include Collection
5
+ include Attributes
6
6
 
7
7
  def initialize(*args); end
8
8
  end
9
9
 
10
- describe Collection do
10
+ describe Attributes do
11
11
  describe '#coercer' do
12
12
  it 'returns an empty collection when nil or empty' do
13
13
  [nil, '', [], {}].each do |empty_value|
14
- Collection.coercer(empty_value, TestClass, :key).must_equal([])
14
+ Attributes.coercer(empty_value, TestClass, :key).must_equal([])
15
15
  end
16
16
  end
17
17
 
18
18
  it 'returns a single model in a collection when a String' do
19
- Collection.coercer('test', TestClass, :key).size.must_equal(1)
19
+ Attributes.coercer('test', TestClass, :key).size.must_equal(1)
20
20
  end
21
21
 
22
22
  it 'returns a collection of models when a single hash' do
23
- Collection.coercer({ :test1 => 'test1' }, TestClass, :key)
23
+ Attributes.coercer({ :test1 => 'test1' }, TestClass, :key)
24
24
  .size.must_equal(1)
25
25
  end
26
26
 
27
27
  it 'returns a collection of models when multiple hashes' do
28
- Collection.coercer([
28
+ Attributes.coercer([
29
29
  { :test1 => 'test1' }, { :test2 => 'test2' }
30
30
  ], TestClass, :key).size.must_equal(2)
31
31
  end
32
32
 
33
33
  it 'returns a collection of models when a single array' do
34
- Collection.coercer([{ :test3 => 'test3' }], TestClass, :key)
34
+ Attributes.coercer([{ :test3 => 'test3' }], TestClass, :key)
35
35
  .size.must_equal(1)
36
36
  end
37
37
  end
@@ -161,70 +161,5 @@ module Vedeu
161
161
  geometry.east.must_equal(26)
162
162
  end
163
163
  end
164
-
165
- describe '#position' do
166
- it 'centred is true' do
167
- console = IO.console
168
- console.stub :winsize, [25, 80] do
169
- geometry = Geometry.new({ height: 6, width: 18, centred: true })
170
- geometry.position.must_equal({
171
- y: 9,
172
- x: 31,
173
- height: 6,
174
- width: 18,
175
- centred: true,
176
- top: 9,
177
- bottom: 15,
178
- left: 31,
179
- right: 49,
180
- })
181
- end
182
- end
183
-
184
- it 'centred is false and x is set' do
185
- geometry = Geometry.new({ height: 6, width: 18, x: 7 })
186
- geometry.position.must_equal({
187
- y: 1,
188
- x: 7,
189
- height: 6,
190
- width: 18,
191
- centred: false,
192
- top: 1,
193
- bottom: 7,
194
- left: 7,
195
- right: 25,
196
- })
197
- end
198
-
199
- it 'centred is false and y is set' do
200
- geometry = Geometry.new({ height: 6, width: 18, y: 5 })
201
- geometry.position.must_equal({
202
- y: 5,
203
- x: 1,
204
- height: 6,
205
- width: 18,
206
- centred: false,
207
- top: 5,
208
- bottom: 11,
209
- left: 1,
210
- right: 19,
211
- })
212
- end
213
-
214
- it 'centred is false' do
215
- geometry = Geometry.new({ height: 6, width: 18 })
216
- geometry.position.must_equal({
217
- y: 1,
218
- x: 1,
219
- height: 6,
220
- width: 18,
221
- centred: false,
222
- top: 1,
223
- bottom: 7,
224
- left: 1,
225
- right: 19,
226
- })
227
- end
228
- end
229
164
  end
230
165
  end
@@ -13,12 +13,37 @@ module Vedeu
13
13
  })
14
14
  }
15
15
 
16
- it 'has a colour attribute' do
17
- line.colour.must_be_instance_of(Colour)
16
+ describe '#attributes' do
17
+ it 'returns the attributes' do
18
+ line.attributes.must_equal(
19
+ {
20
+ colour: {
21
+ foreground: '#ff0000',
22
+ background: '#000000'
23
+ },
24
+ streams: [],
25
+ style: 'normal'
26
+ }
27
+ )
28
+ end
29
+ end
30
+
31
+ describe '#colour' do
32
+ it 'has a colour attribute' do
33
+ line.colour.must_be_instance_of(Colour)
34
+ end
18
35
  end
19
36
 
20
- it 'has a streams attribute' do
21
- line.streams.must_equal([])
37
+ describe '#streams' do
38
+ it 'has a streams attribute' do
39
+ line.streams.must_equal([])
40
+ end
41
+ end
42
+
43
+ describe '#style' do
44
+ it 'has a style attribute' do
45
+ line.style.must_equal("\e[24m\e[21m\e[27m")
46
+ end
22
47
  end
23
48
 
24
49
  describe '#to_s' do
@@ -9,32 +9,77 @@ module Vedeu
9
9
  background: '#000000'
10
10
  },
11
11
  text: 'Some text',
12
- style: 'normal',
12
+ style: style,
13
13
  width: width,
14
14
  align: align
15
15
  })
16
16
  }
17
+ let(:style) { 'normal' }
17
18
  let(:align) { :left }
18
19
  let(:width) { 9 }
19
20
 
20
- it 'has a colour attribute' do
21
- stream.colour.must_be_instance_of(Colour)
21
+ describe '#colour' do
22
+ it 'has a colour attribute' do
23
+ stream.colour.must_be_instance_of(Colour)
24
+ end
22
25
  end
23
26
 
24
- it 'has a text attribute' do
25
- stream.text.must_equal('Some text')
27
+ describe '#text' do
28
+ it 'has a text attribute' do
29
+ stream.text.must_equal('Some text')
30
+ end
26
31
  end
27
32
 
28
- it 'has a style attribute' do
29
- stream.style.must_equal("\e[24m\e[21m\e[27m")
33
+ describe '#style' do
34
+ it 'has a style attribute' do
35
+ stream.style.must_equal("\e[24m\e[21m\e[27m")
36
+ end
30
37
  end
31
38
 
32
- it 'has a width attribute' do
33
- stream.width.must_equal(9)
39
+ describe '#width' do
40
+ it 'has a width attribute' do
41
+ stream.width.must_equal(9)
42
+ end
34
43
  end
35
44
 
36
- it 'has an align attribute' do
37
- stream.align.must_equal(:left)
45
+ describe '#align' do
46
+ it 'has an align attribute' do
47
+ stream.align.must_equal(:left)
48
+ end
49
+ end
50
+
51
+ describe '#style' do
52
+ describe 'for a single style' do
53
+ let(:style) { 'normal' }
54
+
55
+ it 'returns an escape sequence' do
56
+ stream.style.must_equal("\e[24m\e[21m\e[27m")
57
+ end
58
+ end
59
+
60
+ describe 'for multiple styles' do
61
+ let(:style) { ['normal', 'underline'] }
62
+
63
+ it 'returns an escape sequence for multiple styles' do
64
+ stream.style.must_equal("\e[24m\e[21m\e[27m\e[4m")
65
+ end
66
+ end
67
+
68
+ describe 'for an unknown style' do
69
+ let(:style) { 'unknown' }
70
+
71
+ it 'returns an empty string for an unknown style' do
72
+ stream.style.must_equal('')
73
+ end
74
+ end
75
+
76
+ describe 'for an empty or nil' do
77
+ let(:style) { '' }
78
+
79
+ it 'returns an empty string for empty or nil' do
80
+ stream.style.must_equal('')
81
+ end
82
+ end
38
83
  end
39
84
 
40
85
  describe '#to_s' do
@@ -47,6 +47,7 @@ module Vedeu
47
47
  },
48
48
  lines: []
49
49
  })
50
+
50
51
  Render.call(interface).must_equal(
51
52
  "\e[1;1H \e[1;1H" \
52
53
  "\e[2;1H \e[2;1H" \
data/vedeu.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'vedeu'
7
- spec.version = '0.1.10'
7
+ spec.version = '0.1.12'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
10
  spec.summary = %q{A terminal case of wonderland.}
@@ -26,6 +26,4 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'pry', '0.10.0'
27
27
  spec.add_development_dependency 'rake', '10.3.2'
28
28
  spec.add_development_dependency 'simplecov', '0.9.0'
29
-
30
- spec.add_dependency 'virtus', '1.0.3'
31
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-12 00:00:00.000000000 Z
11
+ date: 2014-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,20 +150,6 @@ dependencies:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
152
  version: 0.9.0
153
- - !ruby/object:Gem::Dependency
154
- name: virtus
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - '='
158
- - !ruby/object:Gem::Version
159
- version: 1.0.3
160
- type: :runtime
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - '='
165
- - !ruby/object:Gem::Version
166
- version: 1.0.3
167
153
  description:
168
154
  email:
169
155
  - gavinlaking@gmail.com
@@ -185,9 +171,9 @@ files:
185
171
  - bin/vedeu
186
172
  - lib/vedeu.rb
187
173
  - lib/vedeu/api/api.rb
188
- - lib/vedeu/api/base.rb
189
174
  - lib/vedeu/api/events.rb
190
175
  - lib/vedeu/api/grid.rb
176
+ - lib/vedeu/api/helpers.rb
191
177
  - lib/vedeu/api/interface.rb
192
178
  - lib/vedeu/api/line.rb
193
179
  - lib/vedeu/api/log.rb
@@ -197,20 +183,14 @@ files:
197
183
  - lib/vedeu/application.rb
198
184
  - lib/vedeu/configuration.rb
199
185
  - lib/vedeu/launcher.rb
200
- - lib/vedeu/models/attributes/background.rb
201
- - lib/vedeu/models/attributes/collection.rb
186
+ - lib/vedeu/models/attributes/attributes.rb
202
187
  - lib/vedeu/models/attributes/colour_translator.rb
203
- - lib/vedeu/models/attributes/foreground.rb
204
- - lib/vedeu/models/attributes/interface_collection.rb
205
- - lib/vedeu/models/attributes/line_collection.rb
206
- - lib/vedeu/models/attributes/stream_collection.rb
207
188
  - lib/vedeu/models/colour.rb
208
189
  - lib/vedeu/models/composition.rb
209
190
  - lib/vedeu/models/geometry.rb
210
191
  - lib/vedeu/models/interface.rb
211
192
  - lib/vedeu/models/line.rb
212
193
  - lib/vedeu/models/stream.rb
213
- - lib/vedeu/models/style.rb
214
194
  - lib/vedeu/output/buffers.rb
215
195
  - lib/vedeu/output/clear.rb
216
196
  - lib/vedeu/output/render.rb
@@ -226,18 +206,14 @@ files:
226
206
  - test/lib/vedeu/api/store_test.rb
227
207
  - test/lib/vedeu/api/view_test.rb
228
208
  - test/lib/vedeu/configuration_test.rb
229
- - test/lib/vedeu/models/attributes/collection_test.rb
209
+ - test/lib/vedeu/models/attributes/attributes_test.rb
230
210
  - test/lib/vedeu/models/attributes/colour_translator_test.rb
231
- - test/lib/vedeu/models/attributes/interface_collection_test.rb
232
- - test/lib/vedeu/models/attributes/line_collection_test.rb
233
- - test/lib/vedeu/models/attributes/stream_collection_test.rb
234
211
  - test/lib/vedeu/models/colour_test.rb
235
212
  - test/lib/vedeu/models/composition_test.rb
236
213
  - test/lib/vedeu/models/geometry_test.rb
237
214
  - test/lib/vedeu/models/interface_test.rb
238
215
  - test/lib/vedeu/models/line_test.rb
239
216
  - test/lib/vedeu/models/stream_test.rb
240
- - test/lib/vedeu/models/style_test.rb
241
217
  - test/lib/vedeu/output/buffers_test.rb
242
218
  - test/lib/vedeu/output/clear_test.rb
243
219
  - test/lib/vedeu/output/render_test.rb
@@ -246,8 +222,6 @@ files:
246
222
  - test/lib/vedeu/support/menu_test.rb
247
223
  - test/lib/vedeu/support/terminal_test.rb
248
224
  - test/stats.sh
249
- - test/support/bench.rb
250
- - test/support/colours.rb
251
225
  - test/support/model_test_data.json
252
226
  - test/test_helper.rb
253
227
  - vedeu.gemspec
@@ -282,18 +256,14 @@ test_files:
282
256
  - test/lib/vedeu/api/store_test.rb
283
257
  - test/lib/vedeu/api/view_test.rb
284
258
  - test/lib/vedeu/configuration_test.rb
285
- - test/lib/vedeu/models/attributes/collection_test.rb
259
+ - test/lib/vedeu/models/attributes/attributes_test.rb
286
260
  - test/lib/vedeu/models/attributes/colour_translator_test.rb
287
- - test/lib/vedeu/models/attributes/interface_collection_test.rb
288
- - test/lib/vedeu/models/attributes/line_collection_test.rb
289
- - test/lib/vedeu/models/attributes/stream_collection_test.rb
290
261
  - test/lib/vedeu/models/colour_test.rb
291
262
  - test/lib/vedeu/models/composition_test.rb
292
263
  - test/lib/vedeu/models/geometry_test.rb
293
264
  - test/lib/vedeu/models/interface_test.rb
294
265
  - test/lib/vedeu/models/line_test.rb
295
266
  - test/lib/vedeu/models/stream_test.rb
296
- - test/lib/vedeu/models/style_test.rb
297
267
  - test/lib/vedeu/output/buffers_test.rb
298
268
  - test/lib/vedeu/output/clear_test.rb
299
269
  - test/lib/vedeu/output/render_test.rb
@@ -302,7 +272,5 @@ test_files:
302
272
  - test/lib/vedeu/support/menu_test.rb
303
273
  - test/lib/vedeu/support/terminal_test.rb
304
274
  - test/stats.sh
305
- - test/support/bench.rb
306
- - test/support/colours.rb
307
275
  - test/support/model_test_data.json
308
276
  - test/test_helper.rb
@@ -1,7 +0,0 @@
1
- module Vedeu
2
- class Background < Virtus::Attribute
3
- def coerce(value)
4
- ColourTranslator.new(value).background
5
- end
6
- end
7
- end
@@ -1,11 +0,0 @@
1
- module Vedeu
2
- module Collection
3
- extend self
4
-
5
- def coercer(value, model, key)
6
- return [] if value.nil? || value.empty?
7
-
8
- [value].flatten.map { |v| model.new(v) }
9
- end
10
- end
11
- end
@@ -1,7 +0,0 @@
1
- module Vedeu
2
- class Foreground < Virtus::Attribute
3
- def coerce(value)
4
- ColourTranslator.new(value).foreground
5
- end
6
- end
7
- end
@@ -1,13 +0,0 @@
1
- module Vedeu
2
- class InterfaceCollection < Virtus::Attribute
3
- def coerce(values)
4
- return [] if values.nil? || values.empty?
5
-
6
- [values].flatten.map do |view_attributes|
7
- stored_attributes = API::Store.query(view_attributes[:name])
8
-
9
- Interface.new(stored_attributes.merge!(view_attributes))
10
- end
11
- end
12
- end
13
- end