cite-me 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/{cite-me.rb → cite_me.rb} +31 -5
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c4ae19bc406910cf09a1546b87a5ec408b9ffa4
|
4
|
+
data.tar.gz: 555c106f7e70681c0bb05144eca93fff9adb028d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f48d9b7a8371f3809cf978fea181d2c1b5f89a795143a095255cdd38c319a314c46c19142eef0878dd4d7d9ce351aee27644710edc664d87e3b2e9a7f4455bb
|
7
|
+
data.tar.gz: 536079f4bdd4c6105df96fbc8706ed86fbc8d2f20189d47b542b19c3b6dcf54ad5d220d1698376ecc86583a72f7e6d28c7ce74a04b584f3ac5a1b74e8bd983aa
|
@@ -1,4 +1,20 @@
|
|
1
1
|
class Cite_Me
|
2
|
+
# Usage:
|
3
|
+
# >> citation = Cite_Me.new
|
4
|
+
# >> source = { type: 'book',
|
5
|
+
# authors: ['Jacob Smith'],
|
6
|
+
# title: 'The Art of Writing Code',
|
7
|
+
# city_of_publication: 'Indianapolis',
|
8
|
+
# publisher: 'Smith, Inc.',
|
9
|
+
# year_of_publication: '1992',
|
10
|
+
# medium: 'Print'}
|
11
|
+
# >> citation.generate_citation(source)
|
12
|
+
# => "Smith, Jacob. <i>The Art of Writing Code</i>. Indianapolis: Smith, Inc., 1992. Print."
|
13
|
+
#
|
14
|
+
# Options:
|
15
|
+
# Currently supported types are 'book', 'magazine', and 'web'
|
16
|
+
# All of these are in 'beta', but should work fine for generating regular citations
|
17
|
+
|
2
18
|
def initialize()
|
3
19
|
end
|
4
20
|
|
@@ -18,7 +34,7 @@ class Cite_Me
|
|
18
34
|
def mla_book_generate_citation(options)
|
19
35
|
clean_options = clean_hash(options)
|
20
36
|
output = ''
|
21
|
-
output << authors(clean_options[:authors])
|
37
|
+
output << authors(clean_options[:authors]) || authors(clean_options[:author])
|
22
38
|
output << "<i>" + clean_options[:title] + "</i>. " if clean_options[:title]
|
23
39
|
output << clean_options[:city_of_publication] + ": " if clean_options[:city_of_publication]
|
24
40
|
output << clean_options[:publisher] + ", " if clean_options[:publisher]
|
@@ -31,7 +47,7 @@ class Cite_Me
|
|
31
47
|
def mla_magazine_generate_citation(options)
|
32
48
|
clean_options = clean_hash(options)
|
33
49
|
output = ''
|
34
|
-
output << authors(clean_options[:authors])
|
50
|
+
output << authors(clean_options[:authors]) || authors(clean_options[:author])
|
35
51
|
output << %{"#{clean_options[:title_of_article]}." }
|
36
52
|
output << "<i>" + clean_options[:title_of_periodical] + "</i> "
|
37
53
|
output << clean_options[:publication_date] + ": "
|
@@ -44,7 +60,7 @@ class Cite_Me
|
|
44
60
|
def mla_web_generate_citation(options)
|
45
61
|
clean_options = clean_hash(options)
|
46
62
|
output = ''
|
47
|
-
output << authors(clean_options[:authors])
|
63
|
+
output << authors(clean_options[:authors]) || authors(clean_options[:author])
|
48
64
|
output << "<i>" + clean_options[:name_of_site] + "</i>. "
|
49
65
|
output << clean_options[:name_of_organization] + ", "
|
50
66
|
output << clean_options[:date_of_creation] + ". "
|
@@ -56,17 +72,27 @@ class Cite_Me
|
|
56
72
|
|
57
73
|
def authors(option)
|
58
74
|
author_string = ''
|
75
|
+
if option.is_a? String
|
76
|
+
# if passed a string, cast it to an array
|
77
|
+
# then rename that array to option to be
|
78
|
+
#consistent with the rest of the method
|
79
|
+
author = []
|
80
|
+
author << option
|
81
|
+
option = author
|
82
|
+
end
|
83
|
+
|
59
84
|
option.each_with_index do |author, index|
|
60
85
|
if author =~ /,/
|
86
|
+
# Doe, John A.
|
61
87
|
author_string += author
|
62
88
|
author_string += index == option.length - 1 ? ". " : "and , "
|
63
89
|
else
|
64
|
-
# John A. Doe
|
90
|
+
# John Doe or John A. Doe
|
65
91
|
name = author.split(" ")
|
66
92
|
middle_initial = author.scan(/ \w\. /)
|
67
93
|
author_string += name.last + ", " + name.first + middle_initial.first.to_s
|
68
94
|
# add a period if it's the last entry and NOT a name with a middle initial
|
69
|
-
author_string += index == option.length - 1 ? ". " : "and
|
95
|
+
author_string += index == option.length - 1 ? ". " : ", and " if middle_initial.empty?
|
70
96
|
end
|
71
97
|
end
|
72
98
|
author_string
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cite-me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Smith
|
@@ -10,15 +10,15 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
|
13
|
+
description: Properly MLA formatted citations (suitable for a bibliography) from a
|
14
|
+
passed hash.
|
15
15
|
email: jacob.wesley.smith@gmail.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- lib/
|
21
|
-
homepage: http://rubygems.org/gems/
|
20
|
+
- lib/cite_me.rb
|
21
|
+
homepage: http://rubygems.org/gems/cite_me
|
22
22
|
licenses:
|
23
23
|
- MIT
|
24
24
|
metadata: {}
|