referencess 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.8.7.6
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!top-level-namespace.html";
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index</a> &raquo;
35
+
36
+
37
+ <span class="title">Top Level Namespace</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Top Level Namespace
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ </dl>
82
+ <div class="clear"></div>
83
+
84
+ <h2>Defined Under Namespace</h2>
85
+ <p class="children">
86
+
87
+
88
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="References.html" title="References (module)">References</a></span>
89
+
90
+
91
+
92
+
93
+ </p>
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+ </div>
104
+
105
+ <div id="footer">
106
+ Generated on Tue Dec 15 21:21:43 2015 by
107
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
+ 0.8.7.6 (ruby-2.2.3).
109
+ </div>
110
+
111
+ </body>
112
+ </html>
@@ -0,0 +1,13 @@
1
+ require 'references/version'
2
+ require 'references/reference'
3
+ require 'references/list'
4
+ require 'references/ebook'
5
+ require 'references/magazine'
6
+ require 'references/book'
7
+ require 'references/name'
8
+
9
+ # This module let define your references using a DSL. Into it you can find:
10
+ # * A List to represent a ordered set of references, that can be format to APA standard.
11
+ # * References to a book, magazine and ebook(e-documents)
12
+ module References
13
+ end
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ require "references"
3
+
4
+ module References
5
+ # Represent a book reference
6
+ class Book < Reference
7
+ # Format book reference to APA standard
8
+ # @return [String] format output
9
+ def formatAPA
10
+ (prettyOutput(@authors.map { |x| x.to_s }) + "(" + @datee.year.to_s + ") " + @title +
11
+ if @subtitle
12
+ ": " + @subtitle + "."
13
+ else
14
+ ""
15
+ end +
16
+ "\n\t"+@serie+". (" + @edition.to_s + ") " +
17
+ "(" + @editionnumber.to_s + ") " +
18
+ @isbn.join(", "))
19
+ end
20
+
21
+ # Set subtitle of document
22
+ # params subtitle [String]
23
+ def subtitle(subtitle)
24
+ @subtitle = subtitle
25
+ end
26
+
27
+ # Set some isbn of document, each isbn is store in a list, you can have some in the same book
28
+ # params isbn [String]
29
+ def isbn(isbn)
30
+ if @isbn.nil?
31
+ @isbn = []
32
+ end
33
+ @isbn << isbn
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ require "references"
3
+ require "date"
4
+
5
+ module References
6
+ # Represents a e-document
7
+ class Ebook < Reference
8
+ attr_accessor :url
9
+ # Format book reference to APA standard
10
+ # @return [String] format output
11
+ def formatAPA
12
+ (prettyOutput(@authors.map { |x| x.to_s }) + "(" + @datee.year.to_s + ") " + @title +
13
+ "\n\t(" + @edition.to_s + ") " +
14
+ "(" + @editionnumber.to_s + ") " +
15
+ @url)
16
+ end
17
+
18
+ # Set the url from get the source of document
19
+ # @param url [String] URL of source
20
+ def url(url)
21
+ @url = url
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,113 @@
1
+ module References
2
+ # Struct of a list
3
+ Node = Struct.new(:value, :next, :back)
4
+
5
+ # Is a double-linked list
6
+ class List
7
+ include Enumerable
8
+ def initialize(*vals)
9
+ if vals.length == 0
10
+ @head = nil
11
+ @last = nil
12
+ else
13
+ for val in vals do
14
+ pushEnd val
15
+ end
16
+ end
17
+ end
18
+
19
+ def each
20
+ aux = @head
21
+ while aux != nil
22
+ yield aux.value
23
+ aux = aux.next
24
+ end
25
+ end
26
+
27
+ def takeFirst
28
+ if (@head==@last)
29
+ if @head == nil
30
+ return nil
31
+ end
32
+ value = @head.value
33
+ @head = nil
34
+ @last = nil
35
+ return value
36
+ else
37
+ value = @head.value
38
+ @head = @head.next
39
+ @head.back = nil
40
+ return value
41
+ end
42
+ end
43
+
44
+ def takeLast
45
+ if (@head==@last)
46
+ if @last == nil
47
+ return nil
48
+ end
49
+ value = @last.value
50
+ @head = nil
51
+ @last = nil
52
+ return value
53
+ else
54
+ value = @last.value
55
+ @last = @last.back
56
+ @last.next = nil
57
+ return value
58
+ end
59
+ end
60
+
61
+ def put(val)
62
+ if @head == nil
63
+ @head = @last = Node.new(val,nil,nil)
64
+ else
65
+ aux = Node.new(val,@head, nil)
66
+ @head.back = aux
67
+ @head = aux
68
+ end
69
+ nil
70
+ end
71
+
72
+ def pushEnd(val)
73
+ if @last==nil
74
+ @head = @last = Node.new(val,nil,nil)
75
+ else
76
+ aux = Node.new(val,nil,@last)
77
+ @last.next = aux
78
+ @last = aux
79
+ end
80
+ nil
81
+ end
82
+
83
+ def length
84
+ aux = @head
85
+ count = 0
86
+ while aux!=nil
87
+ count = count + 1
88
+ aux = aux.next
89
+ end
90
+ count
91
+ end
92
+
93
+ def head
94
+ if @head != nil
95
+ @head.value
96
+ else
97
+ nil
98
+ end
99
+ end
100
+
101
+ def last
102
+ if @last != nil
103
+ @last.value
104
+ else
105
+ nil
106
+ end
107
+ end
108
+
109
+ def to_s
110
+ (self.sort.map { |x| x.formatAPA }).join("\n")
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ require "references"
3
+
4
+ module References
5
+ class Magazine < Reference
6
+ def initialize(&block)
7
+ instance_eval &block
8
+ @title = @title.split(" ").map { |x| if x.length >= 4 then x[0].upcase + x[1..-1] end }.join(" ")
9
+ end
10
+
11
+ def issbn(issbn)
12
+ if @issbn.nil?
13
+ @issbn = []
14
+ end
15
+ @issbn << issbn
16
+ end
17
+
18
+ # Format book reference to APA standard
19
+ # @return [String] format output
20
+ def formatAPA
21
+ (prettyOutput(@authors.map { |x| x.to_s }) + "(" + @datee.year.to_s + ") " + @title +
22
+ "\n\t(" + @edition.to_s + ") " +
23
+ "(" + @editionnumber.to_s + ") " +
24
+ @issbn.join(", "))
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ module References
3
+ # This class let work internal names of authors of a fancy way.
4
+ class Name
5
+ include Comparable
6
+ attr_reader :surnames, :names
7
+ # Make a Name object
8
+ # @param surnames [String] Take string with surnames of person of interest seperated with spaces.
9
+ # @param names [String] Take string with names of person of interest seperated with spaces.
10
+ def initialize(surnames, names)
11
+ @surnames = surnames.split(" ")
12
+ @names = names.split(" ")
13
+ end
14
+ # Define the comparasion of names, in this case is with the first surname.
15
+ def <=>(other)
16
+ other.surnames.first <=> @surnames.first
17
+ end
18
+
19
+ # Let convert a Name object in a human readable String in fancy way too.
20
+ # @return [String]
21
+ def to_s
22
+ @surnames.first + ", " + (@names.map { |x| x[0].upcase }).join(". ") + ". "
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,143 @@
1
+ # coding: utf-8
2
+ module References
3
+ # Represent references to resources in a document, it can be e-documents
4
+ # papers, book and also magazines.
5
+ # To create a #Reference you need know the DSL to make, is so simple:
6
+ # @example
7
+ # @libro = References::Book.new do
8
+ # author :surnames => "Thomas",
9
+ # :names => "Dave"
10
+ # author :surnames => "Hunt",
11
+ # :names => "Andy"
12
+ # author :surnames => "Chad",
13
+ # :names => "Fowler"
14
+ #
15
+ # title "Programming Ruby 1.9 & 2.0"
16
+ # subtitle "The Pragmatic Programmers’ Guide"
17
+ # editorial :serie => "The Facets of Ruby",
18
+ # :edition => "Pragmatic Bookshelf",
19
+ # :editionnumber => 4
20
+ #
21
+ # date :year => 2013, :month => 7, :day => 7
22
+ #
23
+ # isbn "ISBN-13: 978-1937785499"
24
+ # isbn "ISBN-10: 1937785491"
25
+ # end
26
+ class Reference
27
+ include Comparable
28
+ attr_accessor :authors, :datee
29
+ # Take a block
30
+ def initialize(&block)
31
+ instance_eval &block
32
+ end
33
+
34
+ # Let, set a author/s in a Reference. You can define some authors, only calling this n-repeated times
35
+ # @param hash [String]
36
+ def author(hash)
37
+ if @authors.nil?
38
+ @authors = []
39
+ end
40
+ @authors << References::Name.new(hash[:surnames], hash[:names])
41
+ end
42
+
43
+ # A Reference only can have a title. If you call this function twice times this, overwrite the las value
44
+ # @param title [String]
45
+ def title(title)
46
+ @title = title
47
+ end
48
+
49
+ # A Reference only can have a editorial. If you call this function twice times, this overwrite the las value
50
+ # The hash must have a :serie => String, :edition => String, :editionnumber => Number
51
+ # @param editorial [Hash]
52
+ def editorial(editorial)
53
+ @serie = editorial[:serie]
54
+ @edition = editorial[:edition]
55
+ @editionnumber = editorial[:editionnumber]
56
+ end
57
+
58
+ # A Reference only can have a date. If you call this function twice times, this overwrite the las value
59
+ # The hash must have a :year => Number, :month => Number, :day => Number
60
+ # @param date [Hash]
61
+ def date(date)
62
+ @datee = Date.new(date[:year],date[:month],date[:day])
63
+ end
64
+
65
+ # This function let format a array to prettitied its output adding a '&' before to last element.
66
+ # @param array [List]
67
+ # @return String
68
+ def prettyOutput(array)
69
+ if array.length > 1
70
+ array[0..-2].join("") + " & " + array[-1]
71
+ elsif array.length == 1
72
+ array[0]
73
+ else
74
+ ""
75
+ end
76
+ end
77
+
78
+ # Define the method to compare several Reference objects
79
+ def <=>(other)
80
+ int = other.authors <=> @authors
81
+ if int = 0
82
+ int = other.datee <=> @datee
83
+ end
84
+ int
85
+ end
86
+
87
+ # Cuantity of authors set
88
+ def cantidadAuthors()
89
+ @authors.length()
90
+ end
91
+
92
+ # Is have set a title?
93
+ def hasTitle
94
+ if @title then
95
+ true
96
+ else
97
+ false
98
+ end
99
+ end
100
+
101
+ def cantidadSeries
102
+ if @serie!= nil then
103
+ 1
104
+ else
105
+ 0
106
+ end
107
+ end
108
+
109
+ def hasEdition
110
+ if @edition then
111
+ true
112
+ else
113
+ false
114
+ end
115
+ end
116
+
117
+ def hasEditionnumber
118
+ if @editionnumber then
119
+ true
120
+ else
121
+ false
122
+ end
123
+ end
124
+
125
+ def hasDate
126
+ if @datee then
127
+ true
128
+ else
129
+ false
130
+ end
131
+ end
132
+
133
+ def cantidadIsbn
134
+ @isbn.length
135
+ end
136
+
137
+ # Not specification in the Reference abstract class
138
+ def formatAPA
139
+ "Not format abstract class"
140
+ end
141
+ end
142
+
143
+ end