Skip to content
Browse files

Merge pull request #5 from typekit/language_id

expose the language id of a Language
  • Loading branch information...
2 parents c34ea67 + a83ad5f commit b36e9a7da91e0e6a856ee3d1b878b50c38388184 @rcarver rcarver committed
Showing with 31 additions and 7 deletions.
  1. +22 −7 lib/speakeasy/language.rb
  2. +9 −0 spec/language_spec.rb
View
29 lib/speakeasy/language.rb
@@ -14,18 +14,28 @@ def self.supported_language_ids
end
end
- # Public: Iterates over all supported languages
+ # Public: Get an array of all supported languages.
#
- # Returns an enumator over the list of supported languages
- def self.each(&block)
- languages = Dir.glob("#{DATA_DIR}/*").map do |file|
+ # Returns an Array of Speakeasy::Language.
+ def self.all
+ Dir.glob("#{DATA_DIR}/*").map do |file|
Language.new(File.basename(file))
end
- languages.each(&block)
end
- def initialize(language)
- filename = File.join(DATA_DIR, language)
+ # Public: Iterates over all supported languages
+ #
+ # yields a Speakeasy::Language for each supported language.
+ #
+ # Returns an Array of Speakeasy::Language.
+ def self.each(&block)
+ all.each(&block)
+ end
+
+ def initialize(language_id)
+ @language_id = language_id
+
+ filename = File.join(DATA_DIR, language_id)
unless File.exist? filename
raise "The file describing this language doesn't exist in #{DATA_DIR}"
@@ -40,6 +50,11 @@ def initialize(language)
verify
end
+ # Public: Get the unique identifier of this language.
+ #
+ # Returns a String code.
+ attr_reader :language_id
+
# Public: Lists all unicode codepoints required by this language.
#
# It turns out that a required character is a difficult thing to define.
View
9 spec/language_spec.rb
@@ -7,6 +7,10 @@
Speakeasy::Language.supported_language_ids.size.should == SupportedLanguages
end
+ it "can get all supported languages" do
+ Speakeasy::Language.all.size.should == SupportedLanguages
+ end
+
it "can iterate over all supported languages" do
Speakeasy::Language.each.to_a.size.should == SupportedLanguages
end
@@ -15,6 +19,11 @@
subject do
Speakeasy::Language.new("de")
end
+
+ it "has a language_id" do
+ subject.language_id.should == "de"
+ end
+
it "has codepoints" do
subject.respond_to? :codepoints
subject.codepoints.is_a? Array

0 comments on commit b36e9a7

Please sign in to comment.
Something went wrong with that request. Please try again.