Class: MathMetadata::Result
- Inherits:
-
Object
- Object
- MathMetadata::Result
- Includes:
- Enumerable
- Defined in:
- lib/math_metadata_lookup/result.rb
Constant Summary collapse
- FORMATS =
[:ruby, :yaml, :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_text ⇒ Object (also: #to_str)
- #to_xml ⇒ Object
- #to_yaml ⇒ Object
Constructor Details
#initialize(meta = []) ⇒ Result
Returns a new instance of Result.
11 12 13 |
# File 'lib/math_metadata_lookup/result.rb', line 11 def initialize( =[] ) @metadata = end |
Instance Method Details
#<<(val) ⇒ Object
16 17 18 |
# File 'lib/math_metadata_lookup/result.rb', line 16 def <<(val) @metadata << val end |
#each ⇒ Object
21 22 23 24 25 |
# File 'lib/math_metadata_lookup/result.rb', line 21 def each @metadata.each do |site| yield site end end |
#format(f = :ruby) ⇒ Object
28 29 30 |
# File 'lib/math_metadata_lookup/result.rb', line 28 def format( f=:ruby ) self.send "to_#{f}" end |
#to_array ⇒ Object
74 75 76 |
# File 'lib/math_metadata_lookup/result.rb', line 74 def to_array @metadata end |
#to_html ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/math_metadata_lookup/result.rb', line 33 def to_html result = "" @metadata.each do |site| result << %~ <div class="site"> <h3>Site: #{site[:name]}</h3>~ site[:result].each do |entity| result << entity.to_html end result << %~</div>~ end result end |
#to_text ⇒ Object Also known as: to_str
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/math_metadata_lookup/result.rb', line 79 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
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/math_metadata_lookup/result.rb', line 48 def to_xml result = "" result << %~<?xml version="1.0" encoding="utf-8"?> <mml>~ @metadata.each do |site| 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
69 70 71 |
# File 'lib/math_metadata_lookup/result.rb', line 69 def to_yaml @metadata.to_yaml end |