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.
- #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
54 55 56 |
# File 'lib/math_metadata_lookup/result.rb', line 54 def format( f=:ruby ) self.send "to_#{f}" end |
#to_array ⇒ Object
107 108 109 |
# File 'lib/math_metadata_lookup/result.rb', line 107 def to_array @metadata end |
#to_html ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/math_metadata_lookup/result.rb', line 59 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
102 103 104 |
# File 'lib/math_metadata_lookup/result.rb', line 102 def to_json @metadata.to_json end |
#to_text ⇒ Object Also known as: to_str
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/math_metadata_lookup/result.rb', line 112 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/math_metadata_lookup/result.rb', line 75 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
97 98 99 |
# File 'lib/math_metadata_lookup/result.rb', line 97 def to_yaml @metadata.ya2yaml end |