nineteen-eighty-two 0.1.0 → 0.1.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f46e15b6304a47beff3b22b3eecfc36a19314d87
4
- data.tar.gz: 8edb0ae9ea7535e45f03cc2bd0a4bba9d5afc229
3
+ metadata.gz: 333300256f217b8dfadb4c4cd9e4fb0762f07fd2
4
+ data.tar.gz: 2fa6d7ac8d22628cc6fb28faf780edd78450e043
5
5
  SHA512:
6
- metadata.gz: 2e29b9d32afebf91e731a3d4ff36ec5ef713e8296e9730816d4e0c3dc13b5a65c2c122ba604aab0ad5f105a48e754f640842a7aa5b6161237470ec0ceee601cc
7
- data.tar.gz: ab91284f03235968ea6b6d191064be0be223339d46298361a90f10827cd8400cd83b6e202ee3631bfdd9dc4fd8ddf37bb0a1458adc7ad0176bd63bc46d1df5d3
6
+ metadata.gz: 1d1845d8f10db6883e0d4df8f5a4786d51664ed913a66f18f2db05efd524a6ec008210bf82cd0db1675700fb39ccb82179724cac41e1bcf8ce459c095e8636a6
7
+ data.tar.gz: 39415ce95392aa2eb1a0ebe5b1364070e1c9f1859f1c7b9a0a024e88cb237d176996a50a6260fd0ae65cbe3ec3469f06b00f4dc7bb1111b4bd4071cdc19f9249
@@ -14,9 +14,7 @@ module Nineteen
14
14
  if nxt == current
15
15
  count += 1
16
16
  else
17
- result << {
18
- current => count + 1
19
- }
17
+ result << (Span.new current, count + 1)
20
18
  count = 0
21
19
  current = nxt
22
20
  end
@@ -1,55 +1,47 @@
1
1
  module Nineteen
2
2
  module Eighty
3
3
  module Two
4
- module Formatters
5
- class HTMLTableFormatter
4
+ module Formats
5
+ class HTMLTable
6
6
  def self.format text
7
- s = '<!-- %s -->' % text
8
- s << '<table class="sinclair">'
9
-
10
7
  lines = Spectrum[text]
11
- s << self.build_row(self.make_blanks(lines.first))
12
-
13
- lines.each { |line| s << self.build_row(Nineteen::Eighty::Two::Decorators::RunLengthEncoder.encode line) }
14
8
 
15
- s << '</table>'
16
- s
9
+ t = File.read File.open File.join templates_dir, 'table.eruby'
10
+ context = {
11
+ title: text,
12
+ blanks: blanks(lines.first),
13
+ rows: lines.map { |l| row(l) }.join("\n")
14
+ }
15
+ Erubis::Eruby.new(t).evaluate(context).strip
17
16
  end
18
17
 
19
- def self.make_blanks text
20
- a = []
21
- (text.length * 8).times do |bit|
22
- a << { 0 => 1 }
23
- end
24
-
25
- a
18
+ def self.blanks lines
19
+ t = File.read File.open File.join templates_dir, 'row.eruby'
20
+ context = {
21
+ cells: lines.map { |b| cell Span.new(0, 1) }.join
22
+ }
23
+ Erubis::Eruby.new(t).evaluate(context).strip
26
24
  end
27
25
 
28
- def self.convert_line line
29
- line.map! { |i|
30
- {
31
- :class => i.keys[0] == 1 ? "on" : "off",
32
- :colspan => i.values[0]
33
- }
26
+ def self.cell span
27
+ t = File.read File.open File.join templates_dir, 'cell.eruby'
28
+ context = {
29
+ style: span.type == 1 ? 'on' : 'off',
34
30
  }
31
+ context[:colspan] = span.width if span.width > 1
32
+ Erubis::Eruby.new(t).evaluate(context).strip
35
33
  end
36
34
 
37
- def self.build_row line
38
- s = '<tr class="sinclair">'
39
-
40
- convert_line line
41
-
42
- line.each do |bit|
43
- s << '<td class="%s"' % bit[:class]
44
- if bit[:colspan] > 1
45
- s << ' colspan="%d"' % bit[:colspan]
46
- end
47
- s << '> </td>'
48
- end
49
-
50
- s << '</tr>'
35
+ def self.row list
36
+ t = File.read File.open File.join templates_dir, 'row.eruby'
37
+ context = {
38
+ cells: Decorators::RunLengthEncoder.encode(list).map { |i| cell i }.join
39
+ }
40
+ Erubis::Eruby.new(t).evaluate(context).strip
41
+ end
51
42
 
52
- s
43
+ def self.templates_dir
44
+ File.join File.dirname(__FILE__),'..', 'templates', 'html', 'table'
53
45
  end
54
46
  end
55
47
  end
@@ -1,8 +1,8 @@
1
1
  module Nineteen
2
2
  module Eighty
3
3
  module Two
4
- module Formatters
5
- class JSONFormatter
4
+ module Formats
5
+ class JSON
6
6
  def self.format text
7
7
  {
8
8
  id: text,
@@ -0,0 +1,53 @@
1
+ module Nineteen
2
+ module Eighty
3
+ module Two
4
+ module Formats
5
+ class SVG
6
+ def self.format text, options = {}
7
+ t = File.read File.open File.join templates_dir, 'document.eruby'
8
+ context = {
9
+ width: text.length * 8,
10
+ height: 8,
11
+ fill_colour: options.fetch(:on_colour, '#000000'),
12
+ body: body(text)
13
+ }
14
+ Erubis::Eruby.new(t).evaluate(context)
15
+ end
16
+
17
+ def self.body text
18
+ rows = []
19
+ Spectrum[text].each_with_index do |line, index|
20
+ rows.push row(line, index)
21
+ end
22
+ rows.join("\n").strip
23
+ end
24
+
25
+ def self.row list, index = 0
26
+ x = 0
27
+ cells = []
28
+ Decorators::RunLengthEncoder.encode(list).each do |item|
29
+ if item.type == 1
30
+ t = File.read File.open File.join templates_dir, 'cell.eruby'
31
+ context = {
32
+ x: x,
33
+ y: index,
34
+ width: item.width,
35
+ height: 1,
36
+ style: 'on'
37
+ }
38
+ cells.push Erubis::Eruby.new(t).evaluate(context)
39
+ end
40
+ x += item.width
41
+ end
42
+
43
+ cells.join("\n").strip
44
+ end
45
+
46
+ def self.templates_dir
47
+ File.join File.dirname(__FILE__),'..', 'templates', 'svg'
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,8 +1,8 @@
1
1
  module Nineteen
2
2
  module Eighty
3
3
  module Two
4
- module Formatters
5
- class TextFormatter
4
+ module Formats
5
+ class Text
6
6
  def self.format text, options = {}
7
7
  on = options.fetch(:on, '1')
8
8
  off = options.fetch(:off, '0')
@@ -0,0 +1 @@
1
+ <td class='<%= @style %>'<% if @colspan %> colspan='<%= @colspan %>'<% end %>> </td>
@@ -0,0 +1 @@
1
+ <tr><%= @cells %></tr>
@@ -0,0 +1,5 @@
1
+ <!-- <%= @title %> -->
2
+ <table class='sinclair'>
3
+ <%= @blanks %>
4
+ <%= @rows %>
5
+ </table>
@@ -0,0 +1 @@
1
+ <rect x='<%= @x %>' y='<%= @y %>' width='<%= @width %>' height='<%= @height %>' class='<%= @style %>' />
@@ -0,0 +1,12 @@
1
+ <svg viewBox='0 0 <%= @width %> <%= @height %>' xmlns='http://www.w3.org/2000/svg'>
2
+ <style type='text/css'>
3
+ <![CDATA[
4
+ rect.on {
5
+ fill: <%= @fill_colour %>;
6
+ }
7
+ ]]>
8
+ </style>
9
+ <g>
10
+ <%= @body %>
11
+ </g>
12
+ </svg>
@@ -1,7 +1,7 @@
1
1
  module Nineteen
2
2
  module Eighty
3
3
  module Two
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
  require 'matrix'
3
+ require 'erubis'
3
4
 
4
5
  require 'nineteen/eighty/two/version'
5
6
  require 'nineteen/eighty/two/spectrum'
@@ -9,3 +10,18 @@ require 'nineteen/eighty/two/decorators/run_length_encoder'
9
10
  require 'nineteen/eighty/two/formatters/text_formatter'
10
11
  require 'nineteen/eighty/two/formatters/json_formatter'
11
12
  require 'nineteen/eighty/two/formatters/html_table_formatter'
13
+ require 'nineteen/eighty/two/formatters/svg_formatter'
14
+
15
+ class Span < Hash
16
+ def initialize type, width
17
+ self[type] = width
18
+ end
19
+
20
+ def type
21
+ self.keys.first
22
+ end
23
+
24
+ def width
25
+ self.values.first
26
+ end
27
+ end
@@ -19,8 +19,10 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
21
21
 
22
+ spec.add_dependency 'erubis'
23
+
22
24
  spec.add_development_dependency 'bundler', '~> 1.12'
23
25
  spec.add_development_dependency 'rake', '~> 10.0'
24
26
  spec.add_development_dependency 'rspec', '~> 3.0'
25
- spec.add_development_dependency 'coveralls', '~> 0.8'
27
+ spec.add_development_dependency 'coveralls', '~> 0.8'
26
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nineteen-eighty-two
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
  - pikesley
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2016-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: erubis
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -88,8 +102,14 @@ files:
88
102
  - lib/nineteen/eighty/two/decorators/run_length_encoder.rb
89
103
  - lib/nineteen/eighty/two/formatters/html_table_formatter.rb
90
104
  - lib/nineteen/eighty/two/formatters/json_formatter.rb
105
+ - lib/nineteen/eighty/two/formatters/svg_formatter.rb
91
106
  - lib/nineteen/eighty/two/formatters/text_formatter.rb
92
107
  - lib/nineteen/eighty/two/spectrum.rb
108
+ - lib/nineteen/eighty/two/templates/html/table/cell.eruby
109
+ - lib/nineteen/eighty/two/templates/html/table/row.eruby
110
+ - lib/nineteen/eighty/two/templates/html/table/table.eruby
111
+ - lib/nineteen/eighty/two/templates/svg/cell.eruby
112
+ - lib/nineteen/eighty/two/templates/svg/document.eruby
93
113
  - lib/nineteen/eighty/two/version.rb
94
114
  - nineteen-eighty-two.gemspec
95
115
  homepage: http://pikesley.org