Class: BibTeX::String
- Includes:
- Replaceable
- Defined in:
- lib/bibtex/elements.rb
Overview
Represents a @string object.
In BibTeX @string objects contain a single string constant assignment. For example, @string{ foo = “bar” } defines the constant ‘foo’; this constant can be used (using BibTeX’s string concatenation syntax) in susbsequent of regular entries.
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Attributes included from Replaceable
Attributes inherited from Element
Instance Method Summary collapse
-
#[](key) ⇒ Object
Retuns the string’s value if parameter matches the key; nil otherwise.
-
#added_to_bibliography(bibliography) ⇒ Object
Called when the element was added to a bibliography.
-
#content ⇒ Object
Returns a string representation of the @string’s content.
-
#initialize(key = nil, value = nil) {|_self| ... } ⇒ String
constructor
Creates a new instance.
-
#removed_from_bibliography(bibliography) ⇒ Object
Called when the element was removed from a bibliography.
- #to_hash(options = {}) ⇒ Object
-
#to_s(options = {}) ⇒ Object
Returns a string representation of the @string object.
- #to_xml(options = {}) ⇒ Object
Methods included from Replaceable
Methods inherited from Element
#<=>, #digest, #has_type?, #inspect, #join, #matches?, #meets?, #meets_all?, #meets_any?, #names, parse, #replace, #to_json, #to_yaml, #type, #values_at
Constructor Details
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
237 238 239 |
# File 'lib/bibtex/elements.rb', line 237 def key @key end |
Instance Method Details
#[](key) ⇒ Object
Retuns the string’s value if parameter matches the key; nil otherwise.
258 259 260 |
# File 'lib/bibtex/elements.rb', line 258 def [](key) @key == key ? @value : nil end |
#added_to_bibliography(bibliography) ⇒ Object
Called when the element was added to a bibliography.
264 265 266 267 268 |
# File 'lib/bibtex/elements.rb', line 264 def added_to_bibliography(bibliography) super bibliography.strings[@key] = self self end |
#content ⇒ Object
Returns a string representation of the @string’s content.
278 279 280 |
# File 'lib/bibtex/elements.rb', line 278 def content "#@key = #{@value.to_s(:quotes => '"')}" end |
#removed_from_bibliography(bibliography) ⇒ Object
Called when the element was removed from a bibliography.
271 272 273 274 275 |
# File 'lib/bibtex/elements.rb', line 271 def removed_from_bibliography(bibliography) super bibliography.strings[@key] = nil self end |
#to_hash(options = {}) ⇒ Object
287 288 289 |
# File 'lib/bibtex/elements.rb', line 287 def to_hash( = {}) { :string => { @key => @value.to_s(:quotes => '"') } } end |
#to_s(options = {}) ⇒ Object
Returns a string representation of the @string object.
283 284 285 |
# File 'lib/bibtex/elements.rb', line 283 def to_s( = {}) "@string{ #{content} }" end |
#to_xml(options = {}) ⇒ Object
291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/bibtex/elements.rb', line 291 def to_xml( = {}) require 'rexml/document' xml = REXML::Element.new(:string) k, v = REXML::Element.new(:key), REXML::Element.new(:value) k.text = key.to_s v.text = value.to_s(:quotes => '"') xml.add_elements(k) xml.add_elements(v) xml end |