cite-me 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/cite_me.rb +28 -18
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b0db38c1ffd2e754041782d7e6267d7a789f83e
|
4
|
+
data.tar.gz: a0d4bb3526f8d0c537007f6119255a6b2ca08a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd7d91f316f65f7514205aaf2977a2d2dbf3ccc4dde63a298468d843a3a1d409514a93771956b4645062bbe94f16ab345793ad74f71896bad9f9cb0c0a5277d2
|
7
|
+
data.tar.gz: 31e27f25ad696956347def3e2e901494faac56f9cfec9f567821947c74ec70514fd23467470f41a80e28943820f3e05ef989413d7612898a2ef36e0c3717f1d1
|
data/lib/cite_me.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
require 'pry'
|
1
2
|
class Cite_Me
|
2
3
|
# Usage:
|
3
4
|
# >> citation = Cite_Me.new
|
4
|
-
# >> source = {
|
5
|
+
# >> source = { source_type: 'book',
|
5
6
|
# authors: ['Jacob Smith'],
|
6
7
|
# title: 'The Art of Writing Code',
|
7
8
|
# city_of_publication: 'Indianapolis',
|
@@ -19,22 +20,22 @@ class Cite_Me
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def generate_citation(options)
|
22
|
-
|
23
|
+
clean_options = clean_hash(options)
|
24
|
+
case clean_options[:source_type]
|
23
25
|
when 'book'
|
24
|
-
mla_book_generate_citation(
|
26
|
+
mla_book_generate_citation(clean_options)
|
25
27
|
when 'magazine'
|
26
|
-
mla_magazine_generate_citation(
|
28
|
+
mla_magazine_generate_citation(clean_options)
|
27
29
|
when 'web'
|
28
|
-
mla_web_generate_citation(
|
30
|
+
mla_web_generate_citation(clean_options)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
32
34
|
private
|
33
35
|
|
34
|
-
def mla_book_generate_citation(
|
35
|
-
clean_options = clean_hash(options)
|
36
|
+
def mla_book_generate_citation(clean_options)
|
36
37
|
output = ''
|
37
|
-
output <<
|
38
|
+
output << author_info(clean_options)
|
38
39
|
output << "<i>" + clean_options[:title] + "</i>. " if clean_options[:title]
|
39
40
|
output << clean_options[:city_of_publication] + ": " if clean_options[:city_of_publication]
|
40
41
|
output << clean_options[:publisher] + ", " if clean_options[:publisher]
|
@@ -44,10 +45,9 @@ class Cite_Me
|
|
44
45
|
output
|
45
46
|
end
|
46
47
|
|
47
|
-
def mla_magazine_generate_citation(
|
48
|
-
clean_options = clean_hash(options)
|
48
|
+
def mla_magazine_generate_citation(clean_options)
|
49
49
|
output = ''
|
50
|
-
output <<
|
50
|
+
output << author_info(clean_options)
|
51
51
|
output << %{"#{clean_options[:title_of_article]}." }
|
52
52
|
output << "<i>" + clean_options[:title_of_periodical] + "</i> "
|
53
53
|
output << clean_options[:publication_date] + ": "
|
@@ -57,12 +57,11 @@ class Cite_Me
|
|
57
57
|
output
|
58
58
|
end
|
59
59
|
|
60
|
-
def mla_web_generate_citation(
|
61
|
-
clean_options = clean_hash(options)
|
60
|
+
def mla_web_generate_citation(clean_options)
|
62
61
|
output = ''
|
63
|
-
output <<
|
62
|
+
output << author_info(clean_options)
|
64
63
|
output << "<i>" + clean_options[:name_of_site] + "</i>. "
|
65
|
-
|
64
|
+
output << clean_options[:name_of_organization] + ", "
|
66
65
|
output << clean_options[:date_of_creation] + ". "
|
67
66
|
output << 'Web. '
|
68
67
|
output << clean_options[:date_of_access] + "."
|
@@ -98,7 +97,11 @@ class Cite_Me
|
|
98
97
|
author_string
|
99
98
|
end
|
100
99
|
|
101
|
-
def
|
100
|
+
def author_info(clean_options)
|
101
|
+
author_info = clean_options[:authors] ? authors(clean_options[:authors]) : authors(clean_options[:author])
|
102
|
+
end
|
103
|
+
|
104
|
+
def year_of_publication(option)
|
102
105
|
if option
|
103
106
|
option.to_s + ". "
|
104
107
|
else
|
@@ -108,11 +111,18 @@ class Cite_Me
|
|
108
111
|
|
109
112
|
def clean_hash(options)
|
110
113
|
clean_options = {}
|
114
|
+
options = options.attributes if !options.is_a? Hash
|
115
|
+
|
116
|
+
## delete any " in key (usually from ActiveRecord object) and turn it to a symbol
|
117
|
+
## we also call to_s on any present values in case a date or year is saved
|
118
|
+
## as an integer in the database
|
111
119
|
options.map do |key, value|
|
112
120
|
if value == ''
|
113
|
-
|
121
|
+
cleaned_key = ( key.is_a? Symbol ) ? key : key.delete('"').to_sym
|
122
|
+
clean_options[cleaned_key] = nil
|
114
123
|
else
|
115
|
-
|
124
|
+
cleaned_key = ( key.is_a? Symbol ) ? key : key.delete('"').to_sym
|
125
|
+
clean_options[cleaned_key] = value
|
116
126
|
end
|
117
127
|
end
|
118
128
|
clean_options
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Smith
|
@@ -10,8 +10,8 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Properly MLA formatted citations (suitable for a bibliography) from
|
14
|
-
|
13
|
+
description: Properly MLA formatted citations (suitable for a bibliography) from ActiveRecord
|
14
|
+
object.attributes or hash.
|
15
15
|
email: jacob.wesley.smith@gmail.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|