Class: Scholar::Citation
- Inherits:
-
Object
- Object
- Scholar::Citation
- Defined in:
- lib/scholar/citation.rb
Overview
A Citation object containing the attributes of the citation and the HTML citation itself.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
The pieces of data in the Citation.
-
#html ⇒ Object
readonly
The actual HTML citation.
-
#raw ⇒ Object
readonly
The raw hash given Citation.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Citation
constructor
Creates a new Citation from the given attributes.
-
#to_hash ⇒ Object
Returns the Citation object in Hash form.
Constructor Details
#initialize(options = {}) ⇒ Citation
Creates a new Citation from the given attributes.
Attributes
-
options
- The attributes of the Citation.
Options
-
:type
- Not optional. The type of source you are citing. -
:contributors
- An array of hashes of contributors.
Examples
citation = Scholar::Citation.new({
:type => :book,
:title => "Foobar",
:contributors => [
{
:role => :author,
:first => "John",
:last => "Sample"
}
]
})
Obviously, you’d include more than that, but you need to see the specific sources for more documentation.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/scholar/citation.rb', line 43 def initialize( = {}) source = "Scholar::Sources::#{[:type].to_s.camelize}".constantize @attributes = @raw = @attributes.clone @attributes.delete(:type) @attributes.each do |k, v| if v.is_a?(Fixnum) @attributes[k] = v.to_s end end @attributes.delete_if {|k, v| v.nil? || v.empty? } if @attributes[:contributors] @attributes = Scholar::Utilities.contributors!(@attributes) end @attributes = Scholar::Utilities.order!(@attributes, source.sequence) attributes = @attributes.clone attributes = Scholar::Utilities.format!(attributes, source.rules) @html = Scholar::Utilities.concatenate!(attributes) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
The pieces of data in the Citation.
11 12 13 |
# File 'lib/scholar/citation.rb', line 11 def attributes @attributes end |
#html ⇒ Object (readonly)
The actual HTML citation.
14 15 16 |
# File 'lib/scholar/citation.rb', line 14 def html @html end |
#raw ⇒ Object (readonly)
The raw hash given Citation.
8 9 10 |
# File 'lib/scholar/citation.rb', line 8 def raw @raw end |
Instance Method Details
#to_hash ⇒ Object
Returns the Citation object in Hash form.
71 72 73 74 75 76 77 78 79 |
# File 'lib/scholar/citation.rb', line 71 def to_hash hash = {} instance_variables.each do |v| hash[v.to_s[1..-1].to_sym] = instance_variable_get(v) end hash end |