Class: Bibtex::Entry
- Inherits:
-
Object
- Object
- Bibtex::Entry
- Defined in:
- lib/bibtex/entry.rb
Overview
A single entry in a bibliography
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add_field(obj, value = nil) ⇒ Object
-
#initialize(type, key) ⇒ Entry
constructor
A new instance of Entry.
- #reject_fields(keys) ⇒ Object
- #select_fields(keys) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(type, key) ⇒ Entry
Returns a new instance of Entry.
7 8 9 10 11 |
# File 'lib/bibtex/entry.rb', line 7 def initialize(type, key) @type = type @key = key @fields = {} end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/bibtex/entry.rb', line 5 def key @key end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/bibtex/entry.rb', line 5 def type @type end |
Instance Method Details
#[](key) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/bibtex/entry.rb', line 21 def [](key) f = @fields[key] if f then f.value else raise "No field with key #{key}" end end |
#add_field(obj, value = nil) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/bibtex/entry.rb', line 13 def add_field(obj, value = nil) if obj.kind_of? Field then @fields[obj.key] = obj else @fields[obj] = Field.new(obj, value) end end |
#reject_fields(keys) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/bibtex/entry.rb', line 35 def reject_fields(keys) r = Entry.new(@type, @key) @fields.each do |k, f| r.add_field f unless keys.index k end return r end |
#select_fields(keys) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/bibtex/entry.rb', line 43 def select_fields(keys) r = Entry.new(@type, @key) @fields.each do |k, f| r.add_field f if keys.index k end return r end |
#to_s ⇒ Object
30 31 32 33 |
# File 'lib/bibtex/entry.rb', line 30 def to_s fs = @fields.collect { |k, f| " #{f.to_s}" }.sort.join ",\n" "@#{@type}{#{@key},\n#{fs}\n}\n\n" end |