Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use arrays for all feature lists instead of having an array here and …

…a hash there
  • Loading branch information...
commit 60df3936cf8686ce33c0091011aec9b034ba9f9c 1 parent d2357f7
Sebastian Kippe skddc authored
2  data/features.json
View
1 addition, 1 deletion not shown
13 lib/trufflepig/feature_list.rb
View
@@ -10,13 +10,24 @@ def self.build
caniuse = JSON.parse File.read("#{File.dirname(__FILE__)}/../../data/caniuse.json")
patterns = JSON.parse File.read("#{File.dirname(__FILE__)}/../../data/patterns.json")
features = caniuse["data"]
+ output = []
+ # Merge detection patterns into feature list
patterns.keys.each do |key|
features[key].merge!({"detection_pattern" => patterns[key]})
end
+ # Transform feature list to an array
+ features.each do |key, feature|
+ output << feature.merge({"id" => key})
+ end
+
+ # Sort array by feature id
+ output.sort!{|a, b| a["id"] <=> b["id"] }
+
+ # Write new features file
of = File.open "#{File.dirname(__FILE__)}/../../data/features.json", "w"
- of.syswrite caniuse["data"].to_json
+ of.syswrite output.to_json
of.close
end
end
4 lib/trufflepig/search.rb
View
@@ -26,9 +26,9 @@ def perform
def scan(file_path)
content = File.read file_path
- features.each do |key, feature|
+ features.each do |feature|
next unless feature["detection_pattern"]
- results << feature.merge({"slug" => key}) if content.match(/#{feature["detection_pattern"]}/)
+ results << feature if content.match(/#{feature["detection_pattern"]}/)
end
end
13 spec/trufflepig/feature_list_spec.rb
View
@@ -7,11 +7,12 @@
end
it "returns a list of features" do
- @features.keys.must_include "video"
- @features.keys.must_include "audio"
- @features.keys.must_include "canvas"
+ feature_keys = @features.collect{|f| f["id"] }
+ feature_keys.must_include "video"
+ feature_keys.must_include "audio"
+ feature_keys.must_include "canvas"
- feature = @features.values_at("video").first
+ feature = @features.select{|f| f["id"] == "video"}.first
feature["categories"].must_equal ["HTML5"]
feature["title"].must_equal "Video element"
end
@@ -24,10 +25,10 @@
end
it "adds detection patterns to the features" do
- feature = @features.values_at("video").first
+ feature = @features.select{|f| f["id"] == "video"}.first
feature["detection_pattern"].must_equal "<video.*>.*<\\/video>"
- feature = @features.values_at("offline-apps").first
+ feature = @features.select{|f| f["id"] == "offline-apps"}.first
feature["detection_pattern"].must_equal "<html.*\\smanifest=.*>"
end
end
4 spec/trufflepig/search_spec.rb
View
@@ -29,7 +29,7 @@
end
it "finds a truffle" do
- @search.results.collect{|f| f["slug"] }.must_include "video"
+ @search.results.collect{|f| f["id"] }.must_include "video"
end
end
@@ -40,7 +40,7 @@
end
it "finds a lot of truffles" do
- feature_keys = @search.results.collect{|f| f["slug"] }
+ feature_keys = @search.results.collect{|f| f["id"] }
feature_keys.must_include "video" # html
feature_keys.must_include "stream" # js
Please sign in to comment.
Something went wrong with that request. Please try again.