glom 0.0.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdd2b6e91b0a8239c19e5f12dc590b7388cd4149
4
- data.tar.gz: 928be18c35eefedf23de5bb48f3934ab911e38e9
3
+ metadata.gz: ba416ce4cedbcf60698ce8a0cf6274c42e36df50
4
+ data.tar.gz: 3a505f25c45a0196d791754b7a145dcf3d5ed26f
5
5
  SHA512:
6
- metadata.gz: 8b9fa9c4f46de8b55bb03f7573efb1af5d09d3671870e5a81bca4cb3bd0cca955ddba26c3946e1d0c877b00e1dcfb3972032ba270b25e453b7e074714341550a
7
- data.tar.gz: 6194bdb79779f339c21ed9ea46eb49f9b63d9b6fb974ddc700d137ff2e3442c95913b558f0227978cab5f16d39f321d1f775d9aca151524913512ef549d78f70
6
+ metadata.gz: a875112507a53c6343ac5b51b965d191e34769e6b873b70214a0118328c9ca4bae91b2dcd727100760741904fbcd3eafa688179f2aa7ed52a50b7572e412929c
7
+ data.tar.gz: 60ddaf79f122cccdd53b7448b9eeda4db0559089f3131bfc8a8356c44cd3543e060f47bfecb3877490908f84a0815040b87461b86e81188b48e4c935916388ea
data/README.md CHANGED
@@ -9,7 +9,6 @@ _To find a package for templating my new js project, I must open github.com and
9
9
  $ glom 'javascript templating'
10
10
 
11
11
  Searching `https://bower-component-list.herokuapp.com` for `templating`...
12
-
13
12
  Searching `http://jiyinyiyong.github.io/nipster/packages.json` for `templating`...
14
13
 
15
14
  +-----------------+-------------------------+---------------+-------+----------------+----------+
@@ -29,23 +28,39 @@ _To find a package for templating my new js project, I must open github.com and
29
28
 
30
29
  ## Contributing
31
30
 
32
- Support for APIs can be added easily by adding `[ApiName].rb` to the `lib/glom/registries` directory.
31
+ Support for APIs can be added easily by adding `[Registry].rb` to the `lib/glom/registries` directory.
32
+
33
+ `[Registry].rb` should be a module with:
33
34
 
34
- `[ApiName].rb` should be a module with a `KEYWORDS` array and a `get()` method.
35
+ - a `KEYWORDS` array
36
+ - a `NAME` string
37
+ - a `URL` string
38
+ - a `BLACKLIST` array (containing package names to exclude)
39
+ - a `standardize()` method that converts `URL` into an array of packages
35
40
 
36
41
  Example:
37
42
 
38
43
  # npm.rb
39
44
 
40
- module Npm
41
- KEYWORDS = ['npm', 'node', 'nodejs', 'js', 'javascript']
45
+ module Bower
46
+ KEYWORDS = ['bower', 'font-end', 'frontend', 'js', 'javascript']
42
47
 
43
48
  def get
44
- # return array of packages here plz
49
+ return [
50
+ ['mustache', 'Minimal templating with {{mustaches}}', 'janl', 5457, '3 months', 'bower'],
51
+ ['hogan', 'A compiler for the mustache templating language', 'twitter', 2912, '25 days', 'bower']
52
+ ]
45
53
  end
46
54
  end
47
55
 
48
- #### Git for ~~losers~~ dummies
56
+ ##### Glom helpers
57
+
58
+ The `Glom` module comes with two built-in helper methods that make standardizing APIs easier:
59
+
60
+ - Glom.get() - Gets a JSON file from the web and caches it, or pulls it from the cache if it exists
61
+ - Glom.match() - Breaks the package description and user's query into array of words and returns a boolean
62
+
63
+ ##### Git for ~~losers~~ dummies
49
64
 
50
65
  1. Fork it
51
66
  2. Create your feature branch (`git checkout -b my-new-feature`)
@@ -3,6 +3,7 @@ require 'rubygems'
3
3
  require 'net/http'
4
4
  require 'json'
5
5
  require 'tmpdir'
6
+ require 'time'
6
7
 
7
8
  # Require individual registry logic
8
9
  Dir["#{File.dirname __FILE__}/glom/registries/*.rb"].each do |file|
@@ -21,7 +22,7 @@ module Glom
21
22
  @@registries_all.each do |registry|
22
23
  registry::KEYWORDS.each do |keyword|
23
24
  if query.include? keyword
24
- (@registries ||= []) << registry
25
+ (@registries ||= []) << registry unless defined? @registries and @registries.include? registry
25
26
  @query.slice! keyword
26
27
  @query.strip!
27
28
  end
@@ -32,10 +33,12 @@ module Glom
32
33
  end
33
34
 
34
35
  def search
36
+ puts ""
37
+
35
38
  @registries.each do |registry|
36
39
  include registry
37
40
 
38
- puts "\nSearching `#{registry::URL}` for `#{@query}`...\n"
41
+ puts "Searching '#{registry::URL}' for '#{@query}'..."
39
42
 
40
43
  (@packages ||= []).concat registry.standardize(@query)
41
44
  end
@@ -43,36 +46,41 @@ module Glom
43
46
 
44
47
  def sort
45
48
  @packages = @packages.sort_by do |package|
46
- -package[3]
49
+ rating = -(package[3] * package.last**3)
50
+ package.pop
51
+ rating
47
52
  end
48
53
  end
49
54
 
50
55
  def display
51
- # Require terminal-table
52
- require 'glom/terminal-table/cell.rb'
53
- require 'glom/terminal-table/core_ext.rb'
54
- require 'glom/terminal-table/row.rb'
55
- require 'glom/terminal-table/separator.rb'
56
- require 'glom/terminal-table/style.rb'
57
- require 'glom/terminal-table/table_helper.rb'
58
- require 'glom/terminal-table/table.rb'
59
- require 'glom/terminal-table/version.rb'
60
-
61
- table = Terminal::Table.new
62
- table.headings = ['Name', 'Description', 'Author', 'Stars', 'Last Updated', 'Registry']
63
- table.rows = @packages[0..20]
64
- table.style = {
65
- :width => `/usr/bin/env tput cols`.to_i
66
- }
67
-
68
- puts ""
69
- puts table
56
+ if @packages.size > 0
57
+ # Require terminal-table
58
+ require 'glom/terminal-table/cell.rb'
59
+ require 'glom/terminal-table/core_ext.rb'
60
+ require 'glom/terminal-table/row.rb'
61
+ require 'glom/terminal-table/separator.rb'
62
+ require 'glom/terminal-table/style.rb'
63
+ require 'glom/terminal-table/table_helper.rb'
64
+ require 'glom/terminal-table/table.rb'
65
+ require 'glom/terminal-table/version.rb'
66
+
67
+ table = Terminal::Table.new
68
+ table.headings = ['Name', 'Description', 'Author', 'Stars', 'Last Updated', 'Registry']
69
+ table.rows = @packages[0..20]
70
+ table.style = {
71
+ :width => `/usr/bin/env tput cols`.to_i
72
+ }
73
+
74
+ puts "\n#{table}\n\n"
75
+ else
76
+ puts "\nNo packages for that query.\n\n"
77
+ end
70
78
  end
71
79
 
72
80
  def get(address)
73
81
  cache = "#{Dir.tmpdir}/#{address.gsub(/[\x00\/\\:\*\?\"<>\|]/, '_').gsub('.json', '')}.json"
74
82
 
75
- if File.exist? cache
83
+ if File.exist?(cache) and File.mtime(cache) > (Time.now - 86400) # there are 86400 seconds in a day
76
84
  json = IO.read(cache)
77
85
  else
78
86
  url = URI.parse(address)
@@ -95,4 +103,13 @@ module Glom
95
103
 
96
104
  return json
97
105
  end
98
- end
106
+
107
+ def match(name, description, query, keywords = [])
108
+ keywords.concat(description.split(/\W+/)).concat(name.split(/-|_/))
109
+ keywords.each(&:downcase!)
110
+
111
+ query = query.downcase.split(/\W+/)
112
+ puts "#{name}: #{(keywords & query).size}" if name == "express" or name == "web-builder"
113
+ (keywords & query).size
114
+ end
115
+ end
@@ -3,19 +3,20 @@ require 'time'
3
3
  require 'glom/time/time_ago_in_words'
4
4
 
5
5
  module Glom::Bower
6
- KEYWORDS = ['bower', 'front-end', 'frontend', 'js', 'javascript']
6
+ KEYWORDS = ['bower', 'front-end', 'frontend', 'js', 'javascript', 'client-side', 'clientside']
7
7
  NAME = 'bower'
8
8
  URL = 'https://bower-component-list.herokuapp.com'
9
+ BLACKLIST = []
9
10
 
10
11
  def standardize(query)
11
12
  json = Glom.get(URL)
12
13
 
13
14
  packages = JSON.parse(json).select do |package|
14
- package['description'].include? query if package['description'].is_a? String
15
+ Glom.match(package['name'], package['description'], query) > 0 and !BLACKLIST.include?(package['name'].downcase) if package['description'].is_a? String
15
16
  end
16
17
 
17
18
  packages.map do |package|
18
- [package['name'], package['description'], package['owner'], package['stars'], Time.parse(package['updated']).time_ago_in_words, NAME]
19
+ [package['name'], package['description'], package['owner'], package['stars'], Time.parse(package['updated']).time_ago_in_words, NAME, Glom.match(package['name'], package['description'], query)]
19
20
  end
20
21
  end
21
22
  end
@@ -3,19 +3,20 @@ require 'time'
3
3
  require 'glom/time/time_ago_in_words'
4
4
 
5
5
  module Glom::Npm
6
- KEYWORDS = ['npm', 'node', 'nodejs', 'js', 'javascript']
6
+ KEYWORDS = ['npm', 'node', 'nodejs', 'js', 'javascript', 'server-side', 'serverside', 'back-end']
7
7
  NAME = 'npm'
8
8
  URL = 'http://jiyinyiyong.github.io/nipster/packages.json'
9
+ BLACKLIST = ['jinja.js', 'joyentexpress']
9
10
 
10
11
  def standardize(query)
11
12
  json = Glom.get(URL)
12
13
 
13
14
  packages = JSON.parse(json)['packages'].select do |package|
14
- package[1].downcase.include? query.downcase if package[1].is_a? String and package[3].is_a? String and !package[5].nil?
15
+ Glom.match(package[0], package[1], query) > 0 and !BLACKLIST.include?(package[0].downcase) if package[1].is_a? String and package[3].is_a? String and !package[5].nil?
15
16
  end
16
17
 
17
18
  packages.map do |package|
18
- [package[0], package[1], package[2], package[5], Time.parse(package[3]).time_ago_in_words, NAME]
19
+ [package[0], package[1], package[2], package[5], Time.parse(package[3]).time_ago_in_words, NAME, Glom.match(package[0], package[1], query) + 1]
19
20
  end
20
21
  end
21
22
  end
@@ -1,3 +1,3 @@
1
1
  module Glom
2
- VERSION = "0.0.6"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jackson Gariety
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-14 00:00:00.000000000 Z
11
+ date: 2013-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler