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
#<=>, #has_type?, #join, #matches?, #meets?, parse, #replace, #to_json, #to_yaml, #type
Constructor Details
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
162 163 164 |
# File 'lib/bibtex/elements.rb', line 162 def key @key end |
Instance Method Details
#[](key) ⇒ Object
Retuns the string’s value if parameter matches the key; nil otherwise.
183 184 185 |
# File 'lib/bibtex/elements.rb', line 183 def [](key) @key == key ? @value : nil end |
#added_to_bibliography(bibliography) ⇒ Object
Called when the element was added to a bibliography.
189 190 191 192 193 |
# File 'lib/bibtex/elements.rb', line 189 def added_to_bibliography(bibliography) super bibliography.strings[@key] = self self end |
#content ⇒ Object
Returns a string representation of the @string’s content.
203 204 205 |
# File 'lib/bibtex/elements.rb', line 203 def content "#@key = #{@value.to_s(:quotes => '"')}" end |
#removed_from_bibliography(bibliography) ⇒ Object
Called when the element was removed from a bibliography.
196 197 198 199 200 |
# File 'lib/bibtex/elements.rb', line 196 def removed_from_bibliography(bibliography) super bibliography.strings[@key] = nil self end |
#to_hash(options = {}) ⇒ Object
212 213 214 |
# File 'lib/bibtex/elements.rb', line 212 def to_hash( = {}) { :string => { @key => @value.to_s(:quotes => '"') } } end |
#to_s(options = {}) ⇒ Object
Returns a string representation of the @string object.
208 209 210 |
# File 'lib/bibtex/elements.rb', line 208 def to_s( = {}) "@string{ #{content} }" end |
#to_xml(options = {}) ⇒ Object
216 217 218 219 220 221 222 223 224 225 |
# File 'lib/bibtex/elements.rb', line 216 def to_xml( = {}) require 'rexml/document' xml = REXML::Element.new(:string) key = REXML::Element.new(:key) val = REXML::Element.new(:value) key.text = @key.to_s val.text = @value.to_s(:quotes => '"') xml end |