Class: MathMetadata::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/math_metadata_lookup/entity.rb

Direct Known Subclasses

Article, Author

Instance Method Summary collapse

Constructor Details

#initialize(meta = {}) ⇒ Entity

Returns a new instance of Entity.



5
6
7
# File 'lib/math_metadata_lookup/entity.rb', line 5

def initialize( meta={} )
  @metadata = meta.dup
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/math_metadata_lookup/entity.rb', line 9

def method_missing( meth, *args )
  case meth.to_s
  when /(.*?)=/
    self[$1] = args.first
  else
    self[meth]
  end
end

Instance Method Details

#[](key) ⇒ Object



18
19
20
# File 'lib/math_metadata_lookup/entity.rb', line 18

def [](key)
  @metadata[key.to_sym]
end

#[]=(key, value) ⇒ Object



22
23
24
# File 'lib/math_metadata_lookup/entity.rb', line 22

def []=(key, value)
  @metadata[key.to_sym] = value
end

#format(f = :ruby) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/math_metadata_lookup/entity.rb', line 26

def format( f=:ruby )
  result = self

  case f.to_sym
  when :text, :html, :xml, :json
    result = self.send("to_#{f}")
  end

  result
end