Class: Bibtex::Bibliography
- Inherits:
-
Object
- Object
- Bibtex::Bibliography
- Defined in:
- lib/bibtex/bibliography.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #<<(e) ⇒ Object
- #[](key) ⇒ Object
-
#initialize ⇒ Bibliography
constructor
A new instance of Bibliography.
-
#map ⇒ Object
Transform the entries in some way and return a new bibliography.
- #save(filename) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Bibliography
Returns a new instance of Bibliography.
8 9 10 |
# File 'lib/bibtex/bibliography.rb', line 8 def initialize @entries = {} end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
6 7 8 |
# File 'lib/bibtex/bibliography.rb', line 6 def entries @entries end |
Instance Method Details
#<<(e) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/bibtex/bibliography.rb', line 12 def <<(e) if e.kind_of? Entry then @entries[e.key] = e else raise 'Cannot add non-entries to bibliography' end end |
#[](key) ⇒ Object
20 21 22 |
# File 'lib/bibtex/bibliography.rb', line 20 def [](key) @entries[key] or raise "No entry #{key}" end |
#map ⇒ Object
Transform the entries in some way and return a new bibliography
26 27 28 29 30 31 32 |
# File 'lib/bibtex/bibliography.rb', line 26 def map r = Bibliography.new @entries.each do |k, e| r << yield(e) end return r end |
#save(filename) ⇒ Object
34 35 36 37 38 |
# File 'lib/bibtex/bibliography.rb', line 34 def save(filename) f = File.new(filename, 'w') f.puts self.to_s f.close end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/bibtex/bibliography.rb', line 40 def to_s @entries.keys.sort.collect { |k| @entries[k].to_s }.join end |