scholar-rename 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/renamer.rb +24 -12
- data/lib/selector.rb +23 -11
- data/lib/version.rb +3 -1
- data/readme.md +22 -6
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79107ab113b4a37427bee2fd9a2996a46ec3bbc4
|
4
|
+
data.tar.gz: 3b8f5e99e677875181da3d34782b558894ad2fd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc6e359f1efebc07bce6d59f9202e7ded85a281d4ebb2b59698cfcbeadccb226e5d7ebfd8c996399742f2734fce7b4cde9f3b893b0b11503f2cc7e358f3d576f
|
7
|
+
data.tar.gz: 522fc2acf038c82ddf6b2c3ef783e540dafdf8c830a6d0064739c1503d067ea066ce4900b5acb1d81e6d6b84ac35a8e21ffcbed0961a6e636c619815e0fb0e08
|
data/lib/renamer.rb
CHANGED
@@ -3,32 +3,44 @@ class Renamer
|
|
3
3
|
a1 = args.first
|
4
4
|
@file = File.join(Dir.pwd, a1)
|
5
5
|
|
6
|
-
if
|
7
|
-
puts "scholar-rename: provide a file"
|
8
|
-
elsif a1 == "-v"
|
6
|
+
if a1 == "-v"
|
9
7
|
puts SR::Version
|
8
|
+
elsif @file == Dir.pwd.to_s + '/'
|
9
|
+
puts "usage: scholar-rename [pdf_file]"
|
10
|
+
puts "please specify a pdf file"
|
11
|
+
elsif has_prereq?
|
12
|
+
puts "please install pdftotext to use scholar-rename"
|
13
|
+
puts "osx: brew install xpdf"
|
10
14
|
else
|
11
15
|
rename
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
19
|
+
def has_prereq?
|
20
|
+
system("pdftotext 2> /dev/null")
|
21
|
+
$?.success?
|
22
|
+
end
|
23
|
+
|
24
|
+
def rename
|
25
|
+
raw = `pdftotext -q '#{@file}' -` # may contain non-ascii characters
|
26
|
+
content = raw.encode('UTF-8', :invalid => :replace, :undef => :replace)
|
27
|
+
|
28
|
+
# for debugging
|
29
|
+
#now = Time.now.to_i.to_s # current time, unique temp file
|
30
|
+
#temp = File.join(Dir.pwd, "temp-scholar-rename-text-#{now}")
|
31
|
+
#system("pdftotext -q '#{@file}' '#{temp}'")
|
20
32
|
|
21
33
|
# Choose pdf qualities
|
22
34
|
s = Selector.new(content)
|
23
35
|
s.select_all # choose props
|
24
36
|
printf "Ok? [Yn]: "
|
25
|
-
conf = STDIN.gets.chomp # confirm title
|
26
37
|
|
27
|
-
begin
|
38
|
+
begin
|
39
|
+
conf = STDIN.gets.chomp # confirm title
|
28
40
|
File.rename(@file, s.title) unless conf.match(/^(n|N).*/)
|
29
|
-
ensure
|
41
|
+
ensure
|
30
42
|
puts "Cleaning up..."
|
31
|
-
File.delete(temp)
|
43
|
+
#File.delete(temp)
|
32
44
|
end
|
33
45
|
end
|
34
46
|
end
|
data/lib/selector.rb
CHANGED
@@ -2,29 +2,40 @@
|
|
2
2
|
# I wonder if this could be augmented with information from google scholar
|
3
3
|
# somehow, there is probably a ruby (or at least python) api.
|
4
4
|
|
5
|
+
require 'colored'
|
6
|
+
|
7
|
+
class String
|
8
|
+
alias_method :bow, :black_on_white
|
9
|
+
end
|
10
|
+
|
5
11
|
class Selector
|
6
12
|
attr_reader :title
|
7
13
|
|
8
14
|
# take the first 10 lines of the pdftotext output and assign it to the
|
9
15
|
# context class instance variable, use later when choosing selector
|
16
|
+
# https://stackoverflow.com/questions/9503554/
|
10
17
|
def initialize(c)
|
11
|
-
@content = c.split("\n")[0..14]
|
18
|
+
@content = c.split("\n")[0..14]
|
19
|
+
.reject {|x| x.length < 2 }
|
20
|
+
.map {|x| x[0..100] } # trim
|
12
21
|
@fulltxt = c.split("\n")
|
13
22
|
end
|
14
23
|
|
15
24
|
def select_all
|
16
|
-
puts "
|
17
|
-
|
25
|
+
puts "Options:".bow
|
26
|
+
@content.each_with_index {|l, i| puts "#{i}\t#{l}" }
|
27
|
+
printf "Select title line number ".bow
|
28
|
+
title = choose(@content, print: false)
|
18
29
|
|
19
|
-
|
20
|
-
authors = choose
|
30
|
+
printf "Select author line number ".bow
|
31
|
+
authors = choose(@content, print: false)
|
21
32
|
|
22
|
-
puts "Select author form
|
33
|
+
puts "Select author form:".bow
|
23
34
|
author = gen_authors(authors)
|
24
35
|
|
25
36
|
year = gen_year # just read it
|
26
37
|
|
27
|
-
puts "Select desired title
|
38
|
+
puts "Select desired title:".bow
|
28
39
|
@title = choose(gen_forms year, title, author)
|
29
40
|
end
|
30
41
|
|
@@ -33,11 +44,11 @@ class Selector
|
|
33
44
|
# user selects back to the calling method. pretty sketchy way to interpret
|
34
45
|
# the users input as a range or integer, but seems to be working for now.
|
35
46
|
# requires you to check for an array and join it on the downside though
|
36
|
-
def choose(
|
37
|
-
|
38
|
-
printf "
|
47
|
+
def choose(options, print: true)
|
48
|
+
options.each_with_index {|l, i| puts "#{i}\t#{l}" } if print
|
49
|
+
printf "[0 - #{options.length-1}]: ".bow
|
39
50
|
line = STDIN.gets.chomp
|
40
|
-
meta = "
|
51
|
+
meta = "options[#{line}]"
|
41
52
|
mout = eval meta # in theory terrible but this aint a rails app............
|
42
53
|
if mout.is_a? (Array)
|
43
54
|
mout.join ' '
|
@@ -68,6 +79,7 @@ class Selector
|
|
68
79
|
au = a.upcase
|
69
80
|
return [
|
70
81
|
"#{y} #{a} #{t}.pdf",
|
82
|
+
"#{y} - #{a} - #{t}.pdf",
|
71
83
|
"#{a}_#{y}_#{t}.pdf".gsub(" ", "_"),
|
72
84
|
"#{au}_#{y}_#{t}.pdf".gsub(" ", "_"),
|
73
85
|
"#{ad}_#{y}_#{t}.pdf".gsub(" ", "_"),
|
data/lib/version.rb
CHANGED
data/readme.md
CHANGED
@@ -1,9 +1,25 @@
|
|
1
|
-
# scholar-rename
|
1
|
+
# scholar-rename
|
2
2
|
|
3
|
-
-
|
4
|
-
|
5
|
-
- or other formats based on your selection
|
6
|
-
- by jeremy warner, fall 2016
|
3
|
+
[![MIT](https://img.shields.io/npm/l/alt.svg?style=flat)](http://jeremywrnr.com/mit-license)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/scholar-rename.svg)](https://badge.fury.io/rb/scholar-rename)
|
7
5
|
|
8
|
-
|
6
|
+
an interactive pdf-renamer tool.
|
9
7
|
|
8
|
+
## install
|
9
|
+
|
10
|
+
[sudo] gem install scholar-rename
|
11
|
+
|
12
|
+
you'll also need: https://en.wikipedia.org/wiki/Pdftotext
|
13
|
+
|
14
|
+
## about
|
15
|
+
|
16
|
+
renames a pdf file to author-title-year.pdf or other formats based on your
|
17
|
+
selection. there isn't actually anything scholarly about this tool, though
|
18
|
+
academic people may find it useful for renaming pdfs that come in arbitrarily
|
19
|
+
named file formats. services like mendeley kind of make this not super
|
20
|
+
relevant. it helps when searching for a specific pdf and when labeling pdfs.
|
21
|
+
|
22
|
+
## todo
|
23
|
+
|
24
|
+
- only show index lines once
|
25
|
+
- actually clean up tempfile
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scholar-rename
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Warner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colored
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
84
|
version: '0'
|
71
85
|
requirements: []
|
72
86
|
rubyforge_project:
|
73
|
-
rubygems_version: 2.6.
|
87
|
+
rubygems_version: 2.6.14
|
74
88
|
signing_key:
|
75
89
|
specification_version: 4
|
76
90
|
summary: Rename pdfs based on author/title/year.
|