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.
13 14 15 |
# File 'lib/math_metadata_lookup/result.rb', line 13 def initialize( =[] ) @metadata = end |
Instance Method Details
#<<(val) ⇒ Object
18 19 20 |
# File 'lib/math_metadata_lookup/result.rb', line 18 def <<(val) @metadata << val end |
#each ⇒ Object
23 24 25 26 27 |
# File 'lib/math_metadata_lookup/result.rb', line 23 def each @metadata.each do |site| yield site end end |
#format(f = :ruby) ⇒ Object
30 31 32 |
# File 'lib/math_metadata_lookup/result.rb', line 30 def format( f=:ruby ) self.send "to_#{f}" end |
#to_array ⇒ Object
78 79 80 |
# File 'lib/math_metadata_lookup/result.rb', line 78 def to_array @metadata end |
#to_html ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/math_metadata_lookup/result.rb', line 35 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_text ⇒ Object Also known as: to_str
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/math_metadata_lookup/result.rb', line 83 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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/math_metadata_lookup/result.rb', line 51 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
73 74 75 |
# File 'lib/math_metadata_lookup/result.rb', line 73 def to_yaml @metadata.ya2yaml end |