Class: BibTexFile::Entry
- Inherits:
-
Object
- Object
- BibTexFile::Entry
- Defined in:
- lib/rbbt/sources/bibtex.rb
Constant Summary collapse
- FIELDS =
%w(pmid title author journal pages number volume year abstract)
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#info ⇒ Object
readonly
Returns the value of attribute info.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, type, info) ⇒ Entry
constructor
A new instance of Entry.
- #method_missing(name, *args) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, type, info) ⇒ Entry
Returns a new instance of Entry.
12 13 14 15 16 17 |
# File 'lib/rbbt/sources/bibtex.rb', line 12 def initialize(name, type, info) @name = name @type = type @info = info @fields = info.keys end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rbbt/sources/bibtex.rb', line 19 def method_missing(name, *args) if name.to_s =~ /(.*)=$/ if (FIELDS + @fields).include?($1.to_s) return @info[$1.to_s] = args[0].chomp else raise "No field named '#{ $1 }'" end else if @fields.include?(name.to_s) return @info[name.to_s] else raise "No field named '#{ name }'" end end end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
11 12 13 |
# File 'lib/rbbt/sources/bibtex.rb', line 11 def fields @fields end |
#info ⇒ Object (readonly)
Returns the value of attribute info.
11 12 13 |
# File 'lib/rbbt/sources/bibtex.rb', line 11 def info @info end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/rbbt/sources/bibtex.rb', line 11 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/rbbt/sources/bibtex.rb', line 11 def type @type end |
Instance Method Details
#to_s ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rbbt/sources/bibtex.rb', line 35 def to_s str = "@#{type}{#{name},\n" FIELDS.each do |field| next if field.nil? str += " #{field} = {#{@info[field]}},\n" end (fields - FIELDS).sort.each do |field| str += " #{field} = {#{@info[field]}},\n" end str += "}" str end |