Class: MathMetadata::Result
- Inherits:
-
Object
- Object
- MathMetadata::Result
- Includes:
- Enumerable
- Defined in:
- lib/math_metadata_lookup/result.rb
Overview
Example of Result class
# initialize search engine
l = MathMetadata::Lookup.new(:verbose => false)
# result containing articles (l.article, l.heuristic, l.reference)
result = l.article(:title => 'sobolev')
result.each do |site|
next unless site[:result]
site[:result].each do |article|
puts "#{site[:name]}: #{article[:title]} (#{article[:authors].join('; ')})"
end
end
# result containing authors (l.author)
result = l.(:name => 'Vesely, Jiri')
result.each do |site|
next unless site[:result]
site[:result].each do ||
puts "#{site[:name]}: #{[:preferred]} (#{[:forms].join('; ')})"
end
end
Constant Summary collapse
- FORMATS =
[:ruby, :yaml, :json, :xml, :html, :text]
Instance Method Summary collapse
- #<<(val) ⇒ Object
- #each ⇒ Object
- #format(f = :ruby) ⇒ Object
-
#initialize(meta = []) ⇒ Result
constructor
A new instance of Result.
- #num_results ⇒ Object
- #results ⇒ Object
- #size ⇒ Object
- #to_array ⇒ Object
- #to_html ⇒ Object
- #to_json ⇒ Object
- #to_text ⇒ Object (also: #to_str)
- #to_xml ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(meta = []) ⇒ Result
Returns a new instance of Result.
37 38 39 |
# File 'lib/math_metadata_lookup/result.rb', line 37 def initialize( =[] ) @metadata = end |
Instance Method Details
#<<(val) ⇒ Object
42 43 44 |
# File 'lib/math_metadata_lookup/result.rb', line 42 def <<(val) @metadata << val end |
#each ⇒ Object
47 48 49 50 51 |
# File 'lib/math_metadata_lookup/result.rb', line 47 def each @metadata.each do |site| yield site end end |
#format(f = :ruby) ⇒ Object
69 70 71 |
# File 'lib/math_metadata_lookup/result.rb', line 69 def format( f=:ruby ) self.send "to_#{f}" end |
#num_results ⇒ Object
59 60 61 |
# File 'lib/math_metadata_lookup/result.rb', line 59 def num_results @metadata.inject(0){|s,m| s += m[:result].size} end |
#results ⇒ Object
64 65 66 |
# File 'lib/math_metadata_lookup/result.rb', line 64 def results @metadata.inject([]){|s,m| s << m[:result]}.flatten end |
#size ⇒ Object
54 55 56 |
# File 'lib/math_metadata_lookup/result.rb', line 54 def size @metadata.size end |
#to_array ⇒ Object
122 123 124 |
# File 'lib/math_metadata_lookup/result.rb', line 122 def to_array @metadata end |
#to_html ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/math_metadata_lookup/result.rb', line 74 def to_html result = "" @metadata.each do |site| next unless site[:result] result << %~ <div class="site"> <h3>Site: #{site[:name]}</h3>~ site[:result].to_a.each do |entity| result << entity.to_html end result << %~</div>~ end result end |
#to_json ⇒ Object
117 118 119 |
# File 'lib/math_metadata_lookup/result.rb', line 117 def to_json @metadata.to_json end |
#to_text ⇒ Object Also known as: to_str
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/math_metadata_lookup/result.rb', line 127 def to_text result = "" @metadata.each do |site| next unless site[:result] result << "Site: #{site[:name]}\n" result << "URL: #{site[:url]}\n" result << "\n" site[:result].each do |entity| result << entity.to_text end result << "\n" end result end |
#to_xml ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/math_metadata_lookup/result.rb', line 90 def to_xml result = "" result << %~<?xml version="1.0" encoding="utf-8"?> <mml>~ @metadata.each do |site| next unless site[:result] result << %~ <site name="#{site[:name]}">~ site[:result].each do |entity| result << entity.to_xml end result << %~ </site> ~ end result << %~</mml>~ result end |
#to_yaml ⇒ Object
112 113 114 |
# File 'lib/math_metadata_lookup/result.rb', line 112 def to_yaml @metadata.ya2yaml end |