Class: References::Reference

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/references/reference.rb

Overview

Represent references to resources in a document, it can be e-documents papers, book and also magazines. To create a #Reference you need know the DSL to make, is so simple: end

Examples:

@libro = References::Book.new do
 author :surnames => "Thomas",
       :names    => "Dave"
 author :surnames => "Hunt",
        :names    => "Andy"
 author :surnames => "Chad",
        :names    => "Fowler"

 title "Programming Ruby 1.9 & 2.0"
 subtitle "The Pragmatic Programmers’ Guide"
 editorial :serie =>  "The Facets of Ruby",
           :edition => "Pragmatic Bookshelf",
           :editionnumber => 4

 date :year => 2013, :month => 7, :day => 7

 isbn "ISBN-13: 978-1937785499"
 isbn "ISBN-10: 1937785491"

Direct Known Subclasses

Book, Ebook, Magazine

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Reference

Take a block



30
31
32
# File 'lib/references/reference.rb', line 30

def initialize(&block)
  instance_eval &block
end

Instance Attribute Details

#authorsObject

Returns the value of attribute authors.



28
29
30
# File 'lib/references/reference.rb', line 28

def authors
  @authors
end

#dateeObject

Returns the value of attribute datee.



28
29
30
# File 'lib/references/reference.rb', line 28

def datee
  @datee
end

Instance Method Details

#<=>(other) ⇒ Object

Define the method to compare several Reference objects



79
80
81
82
83
84
85
# File 'lib/references/reference.rb', line 79

def <=>(other)
  int = other.authors <=> @authors
  if int = 0
    int = other.datee <=> @datee
  end
  int
end

#author(hash) ⇒ Object

Let, set a author/s in a Reference. You can define some authors, only calling this n-repeated times

Parameters:

  • hash (String)


36
37
38
39
40
41
# File 'lib/references/reference.rb', line 36

def author(hash)
  if @authors.nil?
    @authors = []
  end
  @authors << References::Name.new(hash[:surnames], hash[:names])
end

#cantidadAuthorsObject

Cuantity of authors set



88
89
90
# File 'lib/references/reference.rb', line 88

def cantidadAuthors()
  @authors.length()
end

#cantidadIsbnObject



133
134
135
# File 'lib/references/reference.rb', line 133

def cantidadIsbn
  @isbn.length
end

#cantidadSeriesObject



101
102
103
104
105
106
107
# File 'lib/references/reference.rb', line 101

def cantidadSeries
  if @serie!= nil then
    1
  else
    0
  end
end

#date(date) ⇒ Object

A Reference only can have a date. If you call this function twice times, this overwrite the las value The hash must have a :year => Number, :month => Number, :day => Number

Parameters:

  • date (Hash)


61
62
63
# File 'lib/references/reference.rb', line 61

def date(date)
  @datee = Date.new(date[:year],date[:month],date[:day])
end

#editorial(editorial) ⇒ Object

A Reference only can have a editorial. If you call this function twice times, this overwrite the las value The hash must have a :serie => String, :edition => String, :editionnumber => Number

Parameters:

  • editorial (Hash)


52
53
54
55
56
# File 'lib/references/reference.rb', line 52

def editorial(editorial)
  @serie = editorial[:serie]
  @edition = editorial[:edition]
  @editionnumber = editorial[:editionnumber]
end

#formatAPAObject

Not specification in the Reference abstract class



138
139
140
# File 'lib/references/reference.rb', line 138

def formatAPA
  "Not format abstract class"
end

#hasDateObject



125
126
127
128
129
130
131
# File 'lib/references/reference.rb', line 125

def hasDate
  if @datee then
    true
  else
    false
  end
end

#hasEditionObject



109
110
111
112
113
114
115
# File 'lib/references/reference.rb', line 109

def hasEdition
  if @edition then
    true
  else
    false
  end
end

#hasEditionnumberObject



117
118
119
120
121
122
123
# File 'lib/references/reference.rb', line 117

def hasEditionnumber
  if @editionnumber then
    true
  else
    false
  end
end

#hasTitleObject

Is have set a title?



93
94
95
96
97
98
99
# File 'lib/references/reference.rb', line 93

def hasTitle
  if @title then
    true
  else
    false
  end
end

#prettyOutput(array) ⇒ Object

This function let format a array to prettitied its output adding a ‘&’ before to last element.

Parameters:

Returns:

  • String



68
69
70
71
72
73
74
75
76
# File 'lib/references/reference.rb', line 68

def prettyOutput(array)
  if array.length > 1
    array[0..-2].join("") + " & " + array[-1]
  elsif array.length == 1
    array[0]
  else
    ""
  end
end

#title(title) ⇒ Object

A Reference only can have a title. If you call this function twice times this, overwrite the las value

Parameters:

  • title (String)


45
46
47
# File 'lib/references/reference.rb', line 45

def title(title)
  @title = title
end