Skip to content

Commit

Permalink
Merge 8912731 into 9164f28
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Pikesley committed Dec 4, 2013
2 parents 9164f28 + 8912731 commit 8cb5267
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 79 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Will return content of the form _:text_, rendered in the 1982 Sinclair Spectrum

####/:text/pokrovsky

Will return content of the form _:text_, rendered in the 1982 Sinclair Spectrum character set, but compressed to fit into 7 rows thus:
Will return content of the form _:text_, rendered in the 1982 Sinclair Spectrum character set, but with 1s replaced with 4s, and compressed to fit into 7 rows thus:

* if a character has a blank bottom row, that row will be excised, else
* if a character has a blank top row, that row will be excised, else
Expand Down
56 changes: 0 additions & 56 deletions features/gitfiti.feature

This file was deleted.

56 changes: 56 additions & 0 deletions features/pokrovsky.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@pokrovsky
Feature: get height-adjusted JSON

Scenario: Get Pokrovskied JSON for a single character
When I go to "/a/pokrovsky"
Then the response should be JSON:
"""
{
"id": "a",
"data": [
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 4, 4, 4, 0, 0, 0],
[0, 0, 0, 0, 0, 4, 0, 0],
[0, 0, 4, 4, 4, 4, 0, 0],
[0, 4, 0, 0, 0, 4, 0, 0],
[0, 0, 4, 4, 4, 4, 0, 0]
]
}
"""

Scenario: Get height-adjusted JSON for longer string
When I go to "/1982/gitfiti"
Then the response should be JSON:
"""
{
"id": "1982",
"data": [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 4, 4, 0, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4,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0, 0, 0, 4, 4, 4, 4, 0, 0],
[0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 0, 0, 0, 0, 4, 0, 0, 4, 0, 0, 0, 0, 0, 0],
[0, 0, 4, 4, 4, 4, 4, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0]
]
}
"""
2 changes: 1 addition & 1 deletion features/support/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Before('@json, @gitfiti') do
Before('@json, @gitfiti, @pokrovsky') do
add_headers(
{
'Accept' => 'application/json'
Expand Down
4 changes: 2 additions & 2 deletions features/support/paths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def path_to(page_name)
when /a b c/
'/a%20b%20c'

when /a\/gitfiti/
'/a/gitfiti'
when /a\/pokrovsky/
'/a/pokrovsky'

when /a/
'/a'
Expand Down
7 changes: 4 additions & 3 deletions lib/uncle_clive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require_relative 'uncle_clive/formatters/html_table_formatter'
require_relative 'uncle_clive/formatters/png_formatter'
require_relative 'uncle_clive/decorators/run_length_encoder'
require_relative 'uncle_clive/decorators/fourifier'

require 'sinatra/base'
require 'haml'
Expand Down Expand Up @@ -58,9 +59,9 @@ class Spectrum < Sinatra::Base
respond params[:text], true
end

def respond text, gitfiti = false
cs = UncleClive::FontGenerator.new
cs.gitfiti = gitfiti
def respond text, pokvrosky = false
cs = UncleClive::FontGenerator.new
cs.pokrovsky = pokvrosky

request.accept.each do |type|
case type.to_s
Expand Down
29 changes: 29 additions & 0 deletions lib/uncle_clive/decorators/fourifier.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module UncleClive
module Decorators
class Fourifier
def initialize font_generator
@fg = font_generator
end

def [] key
a = []

@fg.get(key).each do |line|
a << (line.map { |i| i * 4 })
end

a
end

def get key
a = []

@fg.get(key).each do |line|
a << (line.map { |i| i * 4 })
end

a
end
end
end
end
16 changes: 8 additions & 8 deletions lib/uncle_clive/font_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

module UncleClive
class FontGenerator
attr_accessor :formatter, :on_char, :off_char, :gitfiti
attr_accessor :formatter, :on_char, :off_char, :pokrovsky

def initialize char_set_file = "conf/character_set.txt"
@char_set_file = char_set_file
@chars = {}
@on_char = "1"
@off_char = "0"
@gitfiti = false
@chars = {}
@on_char = "1"
@off_char = "0"
@pokrovsky = false
get_chars
end

Expand All @@ -19,7 +19,7 @@ def get_chars
key = pieces[1]
values = pieces[2].split(" ").map { |i| i.to_i }

if @gitfiti
if @pokrovsky
if values[-1] == 0
values.pop
elsif values[0] == 0
Expand All @@ -32,8 +32,8 @@ def get_chars
end
end

def gitfiti= bool
@gitfiti = bool
def pokrovsky= bool
@pokrovsky = bool
get_chars
end

Expand Down
3 changes: 3 additions & 0 deletions lib/uncle_clive/formatters/json_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module UncleClive
module Formatters
class JSONFormatter
def render font_generator, key
if font_generator.pokrovsky
font_generator = UncleClive::Decorators::Fourifier.new font_generator
end
{
:id => key.to_s,
:data => font_generator.get(key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Formatters
before :each do
@cs = FontGenerator.new
@cs.formatter = UncleClive::Formatters::JSONFormatter.new
@cs.gitfiti = true
@cs.pokrovsky = true
end

it "should return JSON with 7 lines" do
Expand All @@ -28,13 +28,13 @@ module Formatters
@cs['©'].should == {
:id => "©",
:data => [
[0, 0, 1, 1, 1, 1, 0, 0],
[0, 1, 0, 0, 0, 0, 1, 0],
[1, 0, 0, 1, 1, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 1],
[1, 0, 0, 1, 1, 0, 0, 1],
[0, 1, 0, 0, 0, 0, 1, 0],
[0, 0, 1, 1, 1, 1, 0, 0]
[0, 0, 4, 4, 4, 4, 0, 0],
[0, 4, 0, 0, 0, 0, 4, 0],
[4, 0, 0, 4, 4, 0, 0, 4],
[4, 0, 4, 0, 0, 0, 0, 4],
[4, 0, 0, 4, 4, 0, 0, 4],
[0, 4, 0, 0, 0, 0, 4, 0],
[0, 0, 4, 4, 4, 4, 0, 0]
]
}.to_json
end
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require 'uncle_clive/formatters/html_table_formatter'
require 'uncle_clive/formatters/png_formatter'
require 'uncle_clive/decorators/run_length_encoder'
require 'uncle_clive/decorators/fourifier'

require 'coveralls'
Coveralls.wear!

Expand Down

0 comments on commit 8cb5267

Please sign in to comment.