Top Level Namespace

Defined Under Namespace

Modules: Extcite Classes: Array, String

Instance Method Summary collapse

Instance Method Details

#dir_files(x) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/extcite/utils.rb', line 11

def dir_files(x)
	Dir.entries(x).select { |entry|
		!File.directory? File.join(x, entry) and !(entry =='.' || entry == '..')
	}.map { |z|
		x + '/' + z
	}
end

#make_paths(x) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/extcite/utils.rb', line 19

def make_paths(x)
	path = Array(x)
  if path.length == 1    # if a directory

    if File.directory?(path[0])      # keep only files with .pdf extension

      path = dir_files(path[0]).keep_if { |z| !!z.match(/.pdf/) }
    end
  end

  # check that files exist
  path.each do |z|
    if !File.exist?(z)
      raise z + ' not found'
    end
  end

  return path
end

#pdf_doi(x) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/extcite/utils.rb', line 39

def pdf_doi(x)
  xml = Oga.parse_xml(x)
  begin
    tt = xml.xpath('//rdf:Description')
    return tt.attr('dc:identifier')[0].text.sub(/doi:/, '')
  rescue
    return nil
  end
end

#singlearray2hash(x) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/extcite/utils.rb', line 3

def singlearray2hash(x)
  if x.length == 1 && x.class == Array
    return x[0]
  else
    return x
  end
end