Class: Incite::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/incite/source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Source

Returns a new instance of Source.



7
8
9
10
11
12
13
14
15
# File 'lib/incite/source.rb', line 7

def initialize(attrs={})
  attrs.each do |attr, value|
    self.send("#{attr}=", value)
  end
  self.pages ||= []
  self.authors ||= []
  self.editors ||= []
  self.translators ||= []
end

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



4
5
6
# File 'lib/incite/source.rb', line 4

def authors
  @authors
end

#cityObject

Returns the value of attribute city.



4
5
6
# File 'lib/incite/source.rb', line 4

def city
  @city
end

#editionObject

Returns the value of attribute edition.



4
5
6
# File 'lib/incite/source.rb', line 4

def edition
  @edition
end

#editorsObject

Returns the value of attribute editors.



4
5
6
# File 'lib/incite/source.rb', line 4

def editors
  @editors
end

#pagesObject

Returns the value of attribute pages.



4
5
6
# File 'lib/incite/source.rb', line 4

def pages
  @pages
end

#publisherObject

Returns the value of attribute publisher.



4
5
6
# File 'lib/incite/source.rb', line 4

def publisher
  @publisher
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/incite/source.rb', line 4

def title
  @title
end

#translatorsObject

Returns the value of attribute translators.



4
5
6
# File 'lib/incite/source.rb', line 4

def translators
  @translators
end

#volumeObject

Returns the value of attribute volume.



4
5
6
# File 'lib/incite/source.rb', line 4

def volume
  @volume
end

#yearObject

Returns the value of attribute year.



4
5
6
# File 'lib/incite/source.rb', line 4

def year
  @year
end

Instance Method Details

#citation(type) ⇒ Object



17
18
19
# File 'lib/incite/source.rb', line 17

def citation(type)
  citation = Incite.const_get(type.to_s.capitalize).new(self).to_html
end

#has_attributes?(attrs) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/incite/source.rb', line 21

def has_attributes?(attrs)
  !attrs.map do |attr|
    value = send(attr)
    (value.is_a?(Array) && value.any?) || (!value.is_a?(Array) && !value.nil?)
  end.include?(false)
end