Permalink
Browse files

Expander works

  • Loading branch information...
1 parent 734b7ae commit e6cfbb54fa9b86f22d615f8f21fa729036ad9364 @rcarver rcarver committed May 18, 2010
View
10 lib/fontvariationdescription/compactor.rb
@@ -1,6 +1,5 @@
module FontVariationDescription
class Compactor
- include Item::Helper
def initialize(properties=PROPERTIES, values=VALUES)
@properties = properties
@@ -24,5 +23,14 @@ def parse(input)
result.join('')
end
+ protected
+
+ def get_item(property)
+ if index = @properties.index(property)
+ values = @values[property]
+ Item.new(index, property, values)
+ end
+ end
+
end
end
View
13 lib/fontvariationdescription/expander.rb
@@ -7,6 +7,19 @@ def initialize(properties=PROPERTIES, values=VALUES)
end
def parse(input)
+ return nil unless input && input.size == 2
+
+ result = [nil, nil]
+
+ @properties.each_with_index { |property, index|
+ key = input[index, 1]
+ values = @values[property]
+ item = Item.new(index, property, values)
+ item.expand(result, key)
+ }
+
+ "#{result.join(';')};" if result.all?
end
+
end
end
View
21 lib/fontvariationdescription/item.rb
@@ -0,0 +1,21 @@
+module FontVariationDescription
+ class Item
+
+ def initialize(index, property, values)
+ @index = index
+ @property = property
+ @values = values
+ end
+
+ def compact(output, value)
+ match = @values.find { |v| value == v[1] }
+ output[@index] = match[0] if match
+ end
+
+ def expand(output, value)
+ match = @values.find { |v| value == v[0] }
+ output[@index] = [@property, match[1]].join(':') if match
+ end
+
+ end
+end

0 comments on commit e6cfbb5

Please sign in to comment.