Class: Taxonifi::Model::Ref

Inherits:
Base
  • Object
show all
Defined in:
lib/taxonifi/model/ref.rb

Overview

A basic reference object.

Constant Summary collapse

ATTRIBUTES =

These attributes are set automatically on #new()

[
  :authors,     
  :title, 
  :year,
  :publication,
  :volume,
  :number,
  :pages,
  :pg_start,
  :pg_end,
  :cited_page,   
  :full_citation
]

Instance Attribute Summary collapse

Attributes inherited from Base

#id, #properties, #row_number

Instance Method Summary collapse

Methods inherited from Base

#add_properties, #add_property, #ancestor_ids, #ancestors, #build, #delete_property, #replace_property

Methods included from SharedClassMethods

included

Constructor Details

#initialize(options = {}) ⇒ Ref

If :author_year is passed it is broken down into People + year.

Raises:



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/taxonifi/model/ref.rb', line 50

def initialize(options = {})
  super
  opts = {
  }.merge!(options)
  @parent = nil
  build(ATTRIBUTES, opts)
  @authors = [] if @authors.nil?
  raise Taxonifi::RefError, 'If :author_year is provided then authors and year must not be.' if opts[:author_year] && (!opts[:year].nil? || !opts[:authors].nil?)
  add_author_year(opts[:author_year]) if !opts[:author_year].nil? && opts[:author_year].size > 0
  true
end

Instance Attribute Details

#author_year_indexObject

Return a Taxonifi::Model::AuthorYear representing author/year !! Identical to method in Taxonifi::Model::Name !! Not necessarily unique.



47
48
49
# File 'lib/taxonifi/model/ref.rb', line 47

def author_year_index
  @author_year_index
end

#authorsObject

Array of Taxonifi::Model::Person



24
25
26
# File 'lib/taxonifi/model/ref.rb', line 24

def authors
  @authors
end

#cited_pageObject

String. Some specific page(s) of note.



42
43
44
# File 'lib/taxonifi/model/ref.rb', line 42

def cited_page
  @cited_page
end

#full_citationObject

String. The full text of the citation, as read from input or assigned, not computed from individual components.



44
45
46
# File 'lib/taxonifi/model/ref.rb', line 44

def full_citation
  @full_citation
end

#numberObject

String



34
35
36
# File 'lib/taxonifi/model/ref.rb', line 34

def number
  @number
end

#pagesObject

String. Anything that doesn’t fit in a page range.



36
37
38
# File 'lib/taxonifi/model/ref.rb', line 36

def pages
  @pages
end

#pg_endObject

String



40
41
42
# File 'lib/taxonifi/model/ref.rb', line 40

def pg_end
  @pg_end
end

#pg_startObject

String



38
39
40
# File 'lib/taxonifi/model/ref.rb', line 38

def pg_start
  @pg_start
end

#publicationObject

String



30
31
32
# File 'lib/taxonifi/model/ref.rb', line 30

def publication
  @publication
end

#titleObject

String



26
27
28
# File 'lib/taxonifi/model/ref.rb', line 26

def title
  @title
end

#volumeObject

String



32
33
34
# File 'lib/taxonifi/model/ref.rb', line 32

def volume
  @volume
end

#yearObject

String



28
29
30
# File 'lib/taxonifi/model/ref.rb', line 28

def year
  @year
end

Instance Method Details

#add_author_year(string) ⇒ Object



62
63
64
65
66
# File 'lib/taxonifi/model/ref.rb', line 62

def add_author_year(string)
  auth_yr = Taxonifi::Splitter::Builder.build_author_year(string)
  @year = auth_yr.year
  @authors = auth_yr.people
end

#compact_stringObject

Returns a pipe delimited representation of the reference.



69
70
71
72
# File 'lib/taxonifi/model/ref.rb', line 69

def compact_string
  s = [authors.collect{|a| a.compact_string}.join, year, self.title, publication, volume, number, pages, pg_start, pg_end, cited_page].join("|").downcase.gsub(/\s/, '')
  s
end

#generate_author_year_indexObject

(Re-) generate the author year index.



82
83
84
# File 'lib/taxonifi/model/ref.rb', line 82

def generate_author_year_index
  @author_year_index = Taxonifi::Model::AuthorYear.new(people: @authors, year: @year).compact_index
end

#page_stringObject

Return a single String value representing the page data available for this reference.



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/taxonifi/model/ref.rb', line 88

def page_string
  str = '' 
  if @pg_start.nil?
    str = [@pages].compact.join
  else
    if @pg_end.nil?
      str = [@pg_start, @pages].compact.join("; ")
    else
      str = ["#{@pg_start}-#{@pg_end}", @pages].compact.join("; ")
    end
  end
  str.strip
end