nineteen-eighty-two 0.1.3 → 0.1.4

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8adb225e0b27b75def30e8cbcf6cfaf4d93ec5b
4
- data.tar.gz: 437eb48a19094395b0a30193727bbd36784d3ac2
3
+ metadata.gz: 966a5f8d59bfe35e4a089eb778286579a85502e1
4
+ data.tar.gz: d645dd42ca4b355dec967cb7b741f9dfb2c1d1de
5
5
  SHA512:
6
- metadata.gz: 1853d80dc42dfec864e4e9fde5803aebcd90842d027ec8d7ecb84eb44d8744b236422b0666255e0ee0053f5972f4986c14650bc962fc55e65f1f475a22c588a7
7
- data.tar.gz: d319135567cc68edb911f1ce80a9e68afb329e41d8b2887b389f7087077c29cbee9a6098c7196e711f2ca504ddaa7b3ed9696946dd23d91160a0f39c1f142506
6
+ metadata.gz: b48d485b1a8b55a704aa5c31223e4ca204551db6a184caf5ea55690d0eaceab369579cb11d8cc74dde1cad5610594a400b6b7b4a653d1f23288f4afc1e3c96a4
7
+ data.tar.gz: 9cfbdb519c1cdca9adc18af672fdc22da8e0f606aff002ee7a74daa169cfc73b3ae86bdf1fa93b5ab9048752ab03e5b3b0811ef5f296505e16d7cb3fa0cb399f
@@ -0,0 +1,3 @@
1
+ red: 0xbf0000
2
+ green: 0x00bf00
3
+ blue: 0x0000bf
@@ -0,0 +1,28 @@
1
+ '0': OK
2
+ '1': NEXT without FOR
3
+ '2': Variable not found
4
+ '3': Subscript wrong
5
+ '4': Out of Memory
6
+ '5': Out of screen
7
+ '6': Number too big
8
+ '7': RETURN without GO SUB
9
+ '8': End of file
10
+ '9': STOP statement
11
+ A: Invalid Argument
12
+ B: Integer out of range
13
+ C: Nonsense in BASIC
14
+ D: BREAK
15
+ E: Out of DATA
16
+ F: Invalid file name
17
+ G: No room for line
18
+ H: STOP in INPUT
19
+ I: FOR without NEXT
20
+ J: Invalid I/O device
21
+ K: Invalid colour
22
+ L: BREAK into program
23
+ M: RAMTOP no good
24
+ N: Statement lost
25
+ O: Invalid stream
26
+ P: FN without DEF
27
+ Q: Parameter error
28
+ R: Tape loading error
@@ -4,6 +4,9 @@ require 'erubis'
4
4
 
5
5
  require 'nineteen/eighty/two/version'
6
6
  require 'nineteen/eighty/two/spectrum'
7
+ require 'nineteen/eighty/two/messages'
8
+ require 'nineteen/eighty/two/colours'
9
+ require 'nineteen/eighty/two/exceptions'
7
10
 
8
11
  require 'nineteen/eighty/two/decorators/run_length_encoder'
9
12
 
@@ -0,0 +1,33 @@
1
+ module Nineteen
2
+ module Eighty
3
+ module Two
4
+ class Colours
5
+
6
+ PRIMARIES = YAML.load_file File.join File.dirname(__FILE__), '..', '..', '..', '..', 'config', 'colours.yml'
7
+ PRIMARIES.keys.map do |p|
8
+ self.const_set p.upcase, PRIMARIES[p]
9
+ end
10
+
11
+ BLACK = 0
12
+ YELLOW = RED + GREEN
13
+ CYAN = GREEN + BLUE
14
+ MAGENTA = RED + BLUE
15
+ WHITE = RED + GREEN + BLUE
16
+
17
+ def self.[] key
18
+ hex = "%06x" % (self.const_get key.upcase)
19
+ return brighten hex if key.upcase == key
20
+ hex
21
+ end
22
+
23
+ def self.method_missing m, *args
24
+ self[m]
25
+ end
26
+
27
+ def self.brighten colour
28
+ colour.gsub 'b', 'f'
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module Nineteen
2
+ module Eighty
3
+ module Two
4
+ module Exceptions
5
+ class SpectrumException < Exception
6
+ attr_reader :message
7
+
8
+ def initialize message
9
+ @message = message
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -4,11 +4,11 @@ module Nineteen
4
4
  module Formats
5
5
  class HTMLTable
6
6
  def self.format text
7
- lines = Spectrum[text]
7
+ lines = Spectrum[*text]
8
8
 
9
9
  t = File.read File.open File.join Nineteen::Eighty::Two.templates_dir, 'html', 'table', 'table.eruby'
10
10
  context = {
11
- title: text,
11
+ title: text.to_s.gsub('"', ''),
12
12
  blanks: blanks(lines.first),
13
13
  rows: lines.map { |l| row(l) }.join("\n")
14
14
  }
@@ -5,8 +5,8 @@ module Nineteen
5
5
  class JSON
6
6
  def self.format text
7
7
  {
8
- id: text,
9
- data: Spectrum[text]
8
+ id: text.to_s.gsub('"', ''),
9
+ data: Spectrum[*text]
10
10
  }.to_json
11
11
  end
12
12
  end
@@ -17,16 +17,13 @@ module Nineteen
17
17
  end
18
18
 
19
19
  def self.body text
20
- s = ''
20
+ rows = []
21
21
  text.each_with_index do |line, count|
22
- rows = []
23
22
  Spectrum[line].each_with_index do |line, index|
24
23
  rows.push row(line, index + (count * 8))
25
24
  end
26
- s << rows.join("\n")
27
25
  end
28
-
29
- s.strip
26
+ rows.flatten
30
27
  end
31
28
 
32
29
  def self.row list, index = 0
@@ -42,12 +39,12 @@ module Nineteen
42
39
  height: 1,
43
40
  style: 'on'
44
41
  }
45
- cells.push Erubis::Eruby.new(t).evaluate(context)
42
+ cells.push Erubis::Eruby.new(t).evaluate(context).strip
46
43
  end
47
44
  x += item.width
48
45
  end
49
46
 
50
- cells.join("\n").strip
47
+ cells
51
48
  end
52
49
 
53
50
  def self.longest list
@@ -7,7 +7,11 @@ module Nineteen
7
7
  on = options.fetch(:on, '1')
8
8
  off = options.fetch(:off, '0')
9
9
 
10
- Spectrum[text].map { |t| t.join }.join("\n").gsub('0', off).gsub('1', on)
10
+ Spectrum[*text].map do |t|
11
+ t.join
12
+ end.join("\n").
13
+ gsub('0', off).
14
+ gsub('1', on)
11
15
  end
12
16
  end
13
17
  end
@@ -0,0 +1,43 @@
1
+ module Nineteen
2
+ module Eighty
3
+ module Two
4
+ class Messages
5
+ MESSAGES = YAML.load_file File.join File.dirname(__FILE__), '..', '..', '..', '..', 'config', 'messages.yml'
6
+
7
+ def self.[] key
8
+ key = key.to_s.upcase
9
+ raise Exceptions::SpectrumException.new "Q - #{MESSAGES['Q']}" unless MESSAGES.has_key? key
10
+ "#{key} - #{MESSAGES[key]}"
11
+ end
12
+
13
+ def self.method_missing m, *args
14
+ key = case m
15
+ when :zero
16
+ 0
17
+ when :one
18
+ 1
19
+ when :two
20
+ 2
21
+ when :three
22
+ 3
23
+ when :four
24
+ 4
25
+ when :five
26
+ 5
27
+ when :six
28
+ 6
29
+ when :seven
30
+ 7
31
+ when :eight
32
+ 8
33
+ when :nine
34
+ 9
35
+ else
36
+ m.to_s
37
+ end
38
+ self[key]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -3,9 +3,15 @@ module Nineteen
3
3
  module Two
4
4
  class Spectrum
5
5
  CHARACTERS = YAML.load_file File.join File.dirname(__FILE__), '..', '..', '..', '..', 'config', 'characters.yml'
6
-
7
- def self.[] text
8
- Spectrum.linify text.chars.map { |c| Spectrum.get(c) }
6
+
7
+ def self.[] *text
8
+ # require "pry" ; binding.pry
9
+ a = []
10
+ text.each do |t|
11
+ a += Spectrum.linify(t.chars.map { |c| Spectrum.get(c) })
12
+ end
13
+
14
+ a
9
15
  end
10
16
 
11
17
  def self.get key
@@ -7,6 +7,6 @@
7
7
  ]]>
8
8
  </style>
9
9
  <g>
10
- <%= @body %>
10
+ <%= @body.map { |b| " #{b}" }.join "\n" %>
11
11
  </g>
12
12
  </svg>
@@ -1,7 +1,7 @@
1
1
  module Nineteen
2
2
  module Eighty
3
3
  module Two
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nineteen-eighty-two
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-07 00:00:00.000000000 Z
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis
@@ -98,12 +98,17 @@ files:
98
98
  - bin/console
99
99
  - bin/setup
100
100
  - config/characters.yml
101
+ - config/colours.yml
102
+ - config/messages.yml
101
103
  - lib/nineteen/eighty/two.rb
104
+ - lib/nineteen/eighty/two/colours.rb
102
105
  - lib/nineteen/eighty/two/decorators/run_length_encoder.rb
106
+ - lib/nineteen/eighty/two/exceptions.rb
103
107
  - lib/nineteen/eighty/two/formatters/html_table_formatter.rb
104
108
  - lib/nineteen/eighty/two/formatters/json_formatter.rb
105
109
  - lib/nineteen/eighty/two/formatters/svg_formatter.rb
106
110
  - lib/nineteen/eighty/two/formatters/text_formatter.rb
111
+ - lib/nineteen/eighty/two/messages.rb
107
112
  - lib/nineteen/eighty/two/spectrum.rb
108
113
  - lib/nineteen/eighty/two/templates/html/table/cell.eruby
109
114
  - lib/nineteen/eighty/two/templates/html/table/row.eruby