cites 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/bin/cite +89 -0
  3. data/lib/cites.rb +14 -5
  4. metadata +46 -6
  5. data/bin/crref +0 -9
  6. data/bin/crsearch +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7981c7021e09b78536ea2da88b1babc9e6d93f4e
4
- data.tar.gz: 57d1535b97db170b66f20581fa20ce5f0fade62b
3
+ metadata.gz: c3afd3fc0b33fb6b24c76ca0f073307356e76f30
4
+ data.tar.gz: 158ebe4b49b0aafb6aa397970d4d0d7aebb710d9
5
5
  SHA512:
6
- metadata.gz: 52d393ca56353d91ee08a4967063813e4982dd4a5ccdd18ee400014be19f09ca3df574ac2e14044465bb601ada03aae7fc2972f1042b430afc6320925cc2f0a3
7
- data.tar.gz: 74a13bd74953774843af9be7d4a30baeacf5d55c2391201ba02ad3c6800978615f2a1213c2f3cabeefd76d67e10da922f45e542d645f45be9e947030cc12953b
6
+ metadata.gz: e7816796f8b11dd80ade43380e43f3723ea2e4368d9342adb9858234aa66ac4d5e8c0061ae846755568f8a037e223bc54f21dc7ed93c39c106abd292f0510c05
7
+ data.tar.gz: c550041e4658fb561bd66bbeca9954c05c32e305bbf74ea9aaeb8bbab729c78158643350f06855c3abf55afafadafdeb8702faca8b8e9e9f3bf2f5a5605e441f
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "thor"
4
+
5
+ class Cite < Thor
6
+ include Thor::Actions
7
+ require 'cites'
8
+ require 'launchy'
9
+ require 'json'
10
+ require 'pp'
11
+
12
+ desc "match STRING", "Look for matches in free form citations, get a match and DOI"
13
+ # method_options :doi => :boolean
14
+ def match(tt)
15
+ tt = "#{tt}"
16
+ tt = tt.to_s.split(',')
17
+ out = Cites.match(tt)
18
+ puts out
19
+ end
20
+
21
+ desc "search STRING", "Search for articles via query string or DOI"
22
+ method_option :doi, :default => nil
23
+ method_option :page, :default => nil
24
+ method_option :rows, :default => nil
25
+ method_option :sort, :default => nil
26
+ method_option :year, :default => nil
27
+ def search(tt)
28
+ tt = "#{tt}"
29
+ puts "Searching with query \'#{tt}\'"
30
+ out = Cites.search(tt, options)
31
+
32
+ # Don't use meta for anything for now
33
+ items = out["items"]
34
+ # Restrict output to number of rows fetched even if more was returned
35
+ rows = options['rows'].to_i - 1
36
+ for item in items[0..rows]
37
+ puts "\n"
38
+ puts " Title: #{item['title']}"
39
+ puts " Year: #{item['year']}"
40
+ puts " Normalized score: #{item['normalizedScore']}"
41
+ puts " DOI: #{item['doi']}"
42
+ end
43
+
44
+ # puts "#{tt}"
45
+ # puts opts["doi"] ? out['doi'] : out
46
+ end
47
+
48
+ desc "get citation", "Get a citation from a DOI"
49
+ method_option :format, :default => 'text'
50
+ method_option :style, :default => 'apa'
51
+ method_option :locale, :default => 'en-US'
52
+ method_option :cache, :default => true
53
+ def get(tt)
54
+ tt = "#{tt}"
55
+ # puts tt.to_s
56
+ tt = tt.to_s.split(',')
57
+ # puts tt
58
+ begin
59
+ out = Cites.doi2cit(tt, options[:format], options[:style],
60
+ options[:locale], options[:cache])
61
+ rescue Exception => e
62
+ abort(e.message)
63
+ end
64
+
65
+ puts "Found #{out.length} " + (out.length > 1 ? "matches" : "match")
66
+ for entry in out
67
+ if ['citeproc-json'].include? options['format']
68
+ pp entry
69
+ else
70
+ puts entry
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ desc "launch paper", "Open a paper from a given DOI in your default browser"
77
+ method_option :oa, :type => :boolean, :default => 'true'
78
+ def launch(doi)
79
+ if options[:oa]
80
+ url = "http://macrodocs.org/?doi=" + doi
81
+ Launchy.open(url)
82
+ else
83
+ url = "http://dx.doi.org/" + doi
84
+ Launchy.open(url)
85
+ end
86
+ end
87
+ end
88
+
89
+ Cite.start(ARGV)
@@ -21,12 +21,21 @@ def response_ok(code)
21
21
  end
22
22
  end
23
23
 
24
- # Cites: The single class (for now) in cites
24
+ module Cites
25
25
 
26
- class Cites
26
+ @@cache_location = ENV['HOME'] + '/.cites/cache'
27
27
 
28
- class << self; attr_accessor :cache_location end
29
- @cache_location = ENV['HOME'] + '/.cites/cache'
28
+ def self.getcache()
29
+ return @@cache_location
30
+ end
31
+
32
+ def self.setcache(directory)
33
+ if File.directory?(directory)
34
+ @@cache_location = directory
35
+ else
36
+ puts "Directory path #{directory} does not exist"
37
+ end
38
+ end
30
39
 
31
40
  ##
32
41
  # Get a single citation in various formats from a DOI
@@ -343,4 +352,4 @@ end
343
352
  # has to done manually in each static method (because we don't know which
344
353
  # is called first) or then we would need a propers initializer.
345
354
 
346
- APICache.store = Moneta.new(:File, dir: Cites::cache_location)
355
+ APICache.store = Moneta.new(:File, dir: Cites::getcache())
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cites
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chamberlain
@@ -9,8 +9,36 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-22 00:00:00.000000000 Z
12
+ date: 2014-04-19 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.6'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
14
42
  - !ruby/object:Gem::Dependency
15
43
  name: bibtex-ruby
16
44
  requirement: !ruby/object:Gem::Requirement
@@ -95,16 +123,28 @@ dependencies:
95
123
  - - "~>"
96
124
  - !ruby/object:Gem::Version
97
125
  version: '0.7'
126
+ - !ruby/object:Gem::Dependency
127
+ name: launchy
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 2.4.2
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: 2.4.2
98
140
  description: Search for articles, and get citations from DOIs
99
141
  email: myrmecocystus@gmail.com
100
142
  executables:
101
- - crsearch
102
- - crref
143
+ - cite
103
144
  extensions: []
104
145
  extra_rdoc_files: []
105
146
  files:
106
- - bin/crref
107
- - bin/crsearch
147
+ - bin/cite
108
148
  - lib/cites.rb
109
149
  homepage: http://github.com/sckott/cites
110
150
  licenses:
data/bin/crref DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'doiref'
4
-
5
- # if ARGV[1].length == 0
6
-
7
- # end
8
-
9
- puts DOIref.doi2cit(doi=ARGV[0].to_s, format=ARGV[1].to_s, style=ARGV[2].to_s, locale=ARGV[3].to_s)
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'doiref'
4
- puts DOIref.search(ARGV[0])