Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Compactor works

  • Loading branch information...
commit 68ddc83d0e828547834007993e3066ee77c9717b 1 parent 9ce7a52
@rcarver rcarver authored
View
1  lib/fontvariationdescription.rb
@@ -1,3 +1,4 @@
+require File.dirname(__FILE__) + '/fontvariationdescription/item'
require File.dirname(__FILE__) + '/fontvariationdescription/compactor'
require File.dirname(__FILE__) + '/fontvariationdescription/expander'
View
15 lib/fontvariationdescription/compactor.rb
@@ -1,5 +1,6 @@
module FontVariationDescription
class Compactor
+ include Item::Helper
def initialize(properties=PROPERTIES, values=VALUES)
@properties = properties
@@ -7,6 +8,20 @@ def initialize(properties=PROPERTIES, values=VALUES)
end
def parse(input)
+ result = ['n', '4']
+ descriptors = input.split(';')
+
+ descriptors.each { |descriptor|
+ pair = descriptor.gsub(/\s+/, '').split(':')
+ if pair.size == 2
+ property, value = pair
+ if item = get_item(property)
+ item.compact(result, value)
+ end
+ end
+ }
+
+ result.join('')
end
end
View
4 test/compactor_test.rb
@@ -6,7 +6,7 @@ def setup
@compactor = FontVariationDescription::Compactor.new
end
- Data = YAML.load_file(File.dirname(__FILE__) + "/../expand.yml")
+ Data = YAML.load_file(File.dirname(__FILE__) + "/../compact.yml")
Data['tests'].each_with_index do |test, index|
description = test['description']
@@ -16,7 +16,7 @@ def setup
define_method "test_#{index}_#{description.gsub(/\W/, '')}" do
expected = fvd
actual = @compactor.parse(fontface)
- assert_equal actual, expected, description
+ assert_equal expected, actual, description
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.