Class: MathMetadata::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/math_metadata_lookup/site.rb

Overview

Abstract class. Inherit in your sites definition.

Direct Known Subclasses

CEDRAM, DMLCZ, MR, NUMDAM, ZBL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Site

Returns a new instance of Site.

[View source]

16
17
18
# File 'lib/math_metadata_lookup/site.rb', line 16

def initialize( opts={} )
  @options = { :verbose => true }.merge(opts)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object (protected)

[View source]

68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/math_metadata_lookup/site.rb', line 68

def method_missing(meth, *args)
  page = args.first

  case meth.to_s
  when /^list_of_(.*)\?$/
    re = eval("self.class::LIST_OF_#{$1.upcase}_RE")
    return page =~ re
  when /^get_(.*)_m$/
    re = eval("self.class::#{$1.upcase}_RE")
    re_s = eval("self.class::#{$1.upcase}S_RE")
    m, n = args[1,2]
    m ||= 1
    n ||= 1
    res = []
    page.scan(re_s) do |match|
      entry = []
      m.times {|i| entry << match[i].to_s.strip}
      entry << []
      match[m].scan(re) do |form|
        n.times {|i| entry[m] << form[i]}
      end if match[m]
      res << entry
    end 
    return res

  when /^get_(.*)_s$/
    res = []
    what = $1
    re = eval("self.class::#{what.upcase}_RE")
    re_s = eval("self.class::#{what.upcase}S_RE")
    page =~ re_s
    entries = $1
    entries.to_s.strip.scan(re) do |match|
      res << match[0].to_s.strip
    end
    return res

  when /^get_(.*)$/
    match = eval("self.class::#{$1.upcase}_RE").match(page).to_a.map{|x| x.to_s.strip}
    match.shift
    return match.first if args[1].to_i <= 1
    return match
  end
end

Class Method Details

.inherited(site) ⇒ Object

register new site class

[View source]

21
22
23
# File 'lib/math_metadata_lookup/site.rb', line 21

def self.inherited( site )
  SITES << site
end

Instance Method Details

#article(args = {}) ⇒ Object

search for articles

[View source]

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/math_metadata_lookup/site.rb', line 42

def article( args={} )
  opts = {:id => nil, :title => "", :year => "", :authors => [], :references => true}.merge(args)

  page = fetch_article(opts)
  articles = []
  
  return articles unless page

  if list_of_articles?(page)
    articles = get_article_list(page)
  else
    a = get_article(page, opts)
    articles << a unless a[:title].to_s.strip.empty?
  end
  
  #return [] if articles.size == 0
  articles
end

#author(args = {}) ⇒ Object

search for authors

[View source]

27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/math_metadata_lookup/site.rb', line 27

def author( args={} )
  opts = {:name => nil}.merge(args)
  anf = author_name_forms opts[:name]

  authors = []
  anf.each do |af|
    entry = Author.new({:id => af[1], :preferred => af[0], :forms => af[2]})
    authors << entry unless entry[:id].to_s.strip.empty?
  end

  authors
end

#to_jsonObject

[View source]

61
62
63
# File 'lib/math_metadata_lookup/site.rb', line 61

def to_json
  ""
end