eight_corner 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Guardfile +18 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +2 -0
- data/eight_corner.gemspec +29 -0
- data/lib/eight_corner.rb +16 -0
- data/lib/eight_corner/base.rb +277 -0
- data/lib/eight_corner/bounds.rb +38 -0
- data/lib/eight_corner/figure.rb +18 -0
- data/lib/eight_corner/point.rb +64 -0
- data/lib/eight_corner/quadrant.rb +23 -0
- data/lib/eight_corner/string_mapper.rb +133 -0
- data/lib/eight_corner/svg_printer.rb +89 -0
- data/lib/eight_corner/version.rb +3 -0
- data/spec/lib/eight_corner/base_spec.rb +131 -0
- data/spec/lib/eight_corner/string_mapper_spec.rb +58 -0
- data/spec/spec_helper.rb +77 -0
- data/ted_staff_poster.rb +111 -0
- metadata +166 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'eight_corner/string_mapper'
|
2
|
+
include EightCorner
|
3
|
+
|
4
|
+
describe StringMapper do
|
5
|
+
let(:subject) {StringMapper.new}
|
6
|
+
|
7
|
+
describe "group1" do
|
8
|
+
it "should return 3-string groups for short strings" do
|
9
|
+
str = 'something'
|
10
|
+
expect(subject.group1(str, 0)).to eq('som')
|
11
|
+
expect(subject.group1(str, 1)).to eq('eth')
|
12
|
+
expect(subject.group1(str, 2)).to eq('ing')
|
13
|
+
expect(subject.group1(str, 3)).to eq('som')
|
14
|
+
expect(subject.group1(str, 4)).to eq('eth')
|
15
|
+
expect(subject.group1(str, 5)).to eq('ing')
|
16
|
+
expect(subject.group1(str, 6)).to eq('som')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should wrap around to beginning" do
|
20
|
+
# 'alex deanalex deanale'
|
21
|
+
# ^^^
|
22
|
+
# 0 1 2 3 4 5 6
|
23
|
+
|
24
|
+
expect(subject.group1('alex dean', 6)).to eq('ale')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return larger groups for longer strings" do
|
28
|
+
str = 'there are a bunch of characters in this string'
|
29
|
+
|
30
|
+
expect(subject.group1(str, 0)).to eq('there ')
|
31
|
+
expect(subject.group1(str, 1)).to eq('are a ')
|
32
|
+
expect(subject.group1(str, 2)).to eq('bunch ')
|
33
|
+
expect(subject.group1(str, 3)).to eq('of cha')
|
34
|
+
expect(subject.group1(str, 4)).to eq('racter')
|
35
|
+
expect(subject.group1(str, 5)).to eq('s in t')
|
36
|
+
expect(subject.group1(str, 6)).to eq('his st')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "group2" do
|
41
|
+
it "should return each n-th character from the string" do
|
42
|
+
# something something som
|
43
|
+
# 012345601 234560123 456
|
44
|
+
str = 'something'
|
45
|
+
expect(subject.group2(str, 0)).to eq('snh')
|
46
|
+
expect(subject.group2(str, 1)).to eq('ogi')
|
47
|
+
expect(subject.group2(str, 2)).to eq('msn')
|
48
|
+
expect(subject.group2(str, 3)).to eq('eog')
|
49
|
+
expect(subject.group2(str, 4)).to eq('tms')
|
50
|
+
expect(subject.group2(str, 5)).to eq('heo')
|
51
|
+
expect(subject.group2(str, 6)).to eq('itm')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# strings will be of any length
|
58
|
+
# which percentages will be most interesting?
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, make a
|
10
|
+
# separate helper file that requires this one and then use it only in the specs
|
11
|
+
# that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# The settings below are suggested to provide a good initial experience
|
19
|
+
# with RSpec, but feel free to customize to your heart's content.
|
20
|
+
|
21
|
+
# These two settings work together to allow you to limit a spec run
|
22
|
+
# to individual examples or groups you care about by tagging them with
|
23
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
24
|
+
# get run.
|
25
|
+
config.filter_run :focus
|
26
|
+
config.run_all_when_everything_filtered = true
|
27
|
+
|
28
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
29
|
+
# file, and it's useful to allow more verbose output when running an
|
30
|
+
# individual spec file.
|
31
|
+
if config.files_to_run.one?
|
32
|
+
# Use the documentation formatter for detailed output,
|
33
|
+
# unless a formatter has already been configured
|
34
|
+
# (e.g. via a command-line flag).
|
35
|
+
config.default_formatter = 'doc'
|
36
|
+
end
|
37
|
+
|
38
|
+
# Print the 10 slowest examples and example groups at the
|
39
|
+
# end of the spec run, to help surface which specs are running
|
40
|
+
# particularly slow.
|
41
|
+
# config.profile_examples = 10
|
42
|
+
|
43
|
+
# Run specs in random order to surface order dependencies. If you find an
|
44
|
+
# order dependency and want to debug it, you can fix the order by providing
|
45
|
+
# the seed, which is printed after each run.
|
46
|
+
# --seed 1234
|
47
|
+
config.order = :random
|
48
|
+
|
49
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
50
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
51
|
+
# test failures related to randomization by passing the same `--seed` value
|
52
|
+
# as the one that triggered the failure.
|
53
|
+
Kernel.srand config.seed
|
54
|
+
|
55
|
+
# rspec-expectations config goes here. You can use an alternate
|
56
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
57
|
+
# assertions if you prefer.
|
58
|
+
config.expect_with :rspec do |expectations|
|
59
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
60
|
+
# For more details, see:
|
61
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
62
|
+
expectations.syntax = :expect
|
63
|
+
end
|
64
|
+
|
65
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
66
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
67
|
+
config.mock_with :rspec do |mocks|
|
68
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
69
|
+
# For more details, see:
|
70
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
71
|
+
mocks.syntax = :expect
|
72
|
+
|
73
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
74
|
+
# a real object. This is generally recommended.
|
75
|
+
mocks.verify_partial_doubles = true
|
76
|
+
end
|
77
|
+
end
|
data/ted_staff_poster.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'eight_corner'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
### TUNABLES
|
5
|
+
|
6
|
+
width = 2550
|
7
|
+
height = 3300 # kinda deceptive. doc will be cut off at this point if the number
|
8
|
+
# of figures warrants. figs will not be fit into this amount of
|
9
|
+
# vertical space. (they're given square spaces based on width.)
|
10
|
+
cols = 11
|
11
|
+
|
12
|
+
x_margin = 150
|
13
|
+
y_margin = 150
|
14
|
+
|
15
|
+
figure_x_margin = 5
|
16
|
+
figure_y_margin = 5
|
17
|
+
|
18
|
+
log = Logger.new($stderr)
|
19
|
+
log.level = Logger::INFO
|
20
|
+
|
21
|
+
figure_interdependence = true
|
22
|
+
|
23
|
+
### OK, STOP TUNING NOW.
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
figure_width = (width - (x_margin * 2) - (cols * figure_x_margin * 2)) / cols
|
28
|
+
figure_height = figure_width
|
29
|
+
|
30
|
+
base = EightCorner::Base.new(
|
31
|
+
figure_width,
|
32
|
+
figure_height,
|
33
|
+
logger: log
|
34
|
+
)
|
35
|
+
printer = EightCorner::SvgPrinter.new
|
36
|
+
|
37
|
+
|
38
|
+
data = CSV.read('ted_staff.csv', headers: true)
|
39
|
+
figure_count = data.size
|
40
|
+
|
41
|
+
# try to center-ish the last row of figures
|
42
|
+
figures_in_last_row = figure_count % cols
|
43
|
+
last_row_starts_at = figure_count - figures_in_last_row
|
44
|
+
width_of_last_row_data = (figure_width + (figure_x_margin * 2)) * figures_in_last_row
|
45
|
+
unoccupied_last_row_space = width - x_margin*2 - width_of_last_row_data
|
46
|
+
pixel_offset_in_last_row = unoccupied_last_row_space / 2
|
47
|
+
|
48
|
+
# this is necessary to make the last row center properly.
|
49
|
+
# which means i have a math error in here somewhere...
|
50
|
+
# pixel_offset_in_last_row += 30
|
51
|
+
|
52
|
+
svg = printer.svg(width, height) do |p|
|
53
|
+
idx = 0
|
54
|
+
out = ''
|
55
|
+
previous_figure = nil
|
56
|
+
|
57
|
+
data.each do |data|
|
58
|
+
log.debug ['data', data.inspect]
|
59
|
+
|
60
|
+
# out += "<!-- #{data['full']} -->\n"
|
61
|
+
|
62
|
+
previous_potential = previous_figure.nil? ? 0.5 : previous_figure.potential
|
63
|
+
previous_potential = 0.5 if figure_interdependence == false
|
64
|
+
# puts "#{data['full']}\t#{previous_potential}"
|
65
|
+
|
66
|
+
figure = base.plot(data['full'].to_s,
|
67
|
+
point_interdependence: true,
|
68
|
+
initial_potential: previous_potential
|
69
|
+
)
|
70
|
+
|
71
|
+
log.debug ['points', figure.points.inspect]
|
72
|
+
|
73
|
+
|
74
|
+
col = idx % cols
|
75
|
+
figure_x_origin = figure_width * col + (figure_x_margin * col * 2) + x_margin
|
76
|
+
# try to center-ish the last row of figures
|
77
|
+
if idx >= last_row_starts_at
|
78
|
+
figure_x_origin += pixel_offset_in_last_row
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
row = idx/cols
|
84
|
+
figure_y_origin = figure_height * row + (figure_y_margin * row * 2) + y_margin
|
85
|
+
|
86
|
+
out += p.draw(figure,
|
87
|
+
show_border: true,
|
88
|
+
mark_initial_point: true,
|
89
|
+
method: :incremental_colors,
|
90
|
+
label: data['full'],
|
91
|
+
# label: data['full'][0..5] +' '+previous_potential.to_s[0..10],
|
92
|
+
# method: :solid,
|
93
|
+
x_offset: figure_x_origin,
|
94
|
+
y_offset: figure_y_origin,
|
95
|
+
width: figure_width,
|
96
|
+
height: figure_height
|
97
|
+
)
|
98
|
+
idx += 1
|
99
|
+
|
100
|
+
previous_figure = figure
|
101
|
+
end
|
102
|
+
out
|
103
|
+
end
|
104
|
+
|
105
|
+
# filename = File.basename(__FILE__, '.rb')
|
106
|
+
filename = "output"
|
107
|
+
|
108
|
+
svg_filename = "#{filename}.svg"
|
109
|
+
File.open(svg_filename, 'w') {|f| f.write svg }
|
110
|
+
|
111
|
+
`open -a Firefox #{svg_filename}`
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eight_corner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Dean
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: interpolate
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.6.1
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.6.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 4.3.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 4.3.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ruby_gntp
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.3.4
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.3.4
|
111
|
+
description: Map text to graphic figures inspired by Georg Nees 'eight corner' project.
|
112
|
+
email:
|
113
|
+
- alex@crackpot.org
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .rspec
|
120
|
+
- Gemfile
|
121
|
+
- Guardfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- eight_corner.gemspec
|
126
|
+
- lib/eight_corner.rb
|
127
|
+
- lib/eight_corner/base.rb
|
128
|
+
- lib/eight_corner/bounds.rb
|
129
|
+
- lib/eight_corner/figure.rb
|
130
|
+
- lib/eight_corner/point.rb
|
131
|
+
- lib/eight_corner/quadrant.rb
|
132
|
+
- lib/eight_corner/string_mapper.rb
|
133
|
+
- lib/eight_corner/svg_printer.rb
|
134
|
+
- lib/eight_corner/version.rb
|
135
|
+
- spec/lib/eight_corner/base_spec.rb
|
136
|
+
- spec/lib/eight_corner/string_mapper_spec.rb
|
137
|
+
- spec/spec_helper.rb
|
138
|
+
- ted_staff_poster.rb
|
139
|
+
homepage: ''
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.1.11
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: Library for generating abstract figures from text strings.
|
163
|
+
test_files:
|
164
|
+
- spec/lib/eight_corner/base_spec.rb
|
165
|
+
- spec/lib/eight_corner/string_mapper_spec.rb
|
166
|
+
- spec/spec_helper.rb
|