Method: MathMetadata::Site#method_missing

Defined in:
lib/math_metadata_lookup/site.rb

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



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