incite 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ .rbenv-version
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode # JRuby in 1.8 mode
7
+ - jruby-19mode # JRuby in 1.9 mode
8
+ - rbx-18mode
9
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "dust"
7
+ end
8
+
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # Overview [![Incite Build Status][Build Icon]][Build Status]
2
+
3
+ [Build Status]: http://travis-ci.org/tfwright/incite
4
+ [Build Icon]: https://secure.travis-ci.org/tfwright/incite.png?branch=master
5
+
6
+ Incite is in alpha alpha stage. It's useless, don't install it.
7
+
8
+ # Usage
9
+
10
+ * Note: This syntax is very experimental, and will likely--no, definitely--change in a radical way (see above).
11
+
12
+ ```
13
+ irb> require 'lib/incite'
14
+ => true
15
+ ```
16
+
17
+ First you need to instantiate a source you want to cite:
18
+
19
+ ```
20
+ irb> source = Incite::Source.new
21
+ => #<Incite::Source:0x8c5f0>
22
+ ```
23
+
24
+ Sources don't require any parameters to be created, but obviously you're not going to get a very useful citation:
25
+
26
+ ```
27
+ irb> source.citation(:note)
28
+ => ", <em></em> (: , ), ."
29
+ ```
30
+
31
+ So lets add some metadata and try again. When we're talking about citations, proper attribution is usually the most pressing task:
32
+
33
+ ```
34
+ irb> source.authors = ["Some Guy", "Smart Gal"]
35
+ => ["Some Guy", "Smart Gal"]
36
+ irb> source.citation(:note)
37
+ => "Smart Gal and Some Guy, <em></em> (: , ), ."
38
+ ```
39
+
40
+ OK. That's a little better. It's even sorted them for you! Unfortunately...it also spat out a bunch of garbage relating to other unavailable data. In the future the plan is for Incite to be intelligent about how to format 'partial' sources (this has begun to be implemented, but needs to be a lot more robust).
41
+
42
+ # Other future plans
43
+
44
+ * Integration with various bibliographies (Google Books, Amazon, &c?)
45
+ * Citation text
46
+ * Source types
47
+ * Minimal validations of metadata
48
+ * Different type of formats (to_s, to_rtf)
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "incite/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "incite"
7
+ s.version = Incite::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Thomas Wright"]
10
+ s.email = ["tfwright@gmail.com"]
11
+ s.homepage = "http://github.com/tfwright/incite"
12
+ s.summary = %q{Ruby lib for formatting bibliographical data}
13
+ s.description = %q{Incite is an academic citation library that lets you easily define objects for typical academic sources (eg. books, articles) which can be used to output formatted html for a variety of bibliographical formats (eg. Chicago Manual of Style, MLA). Right now only CMS is supported. Incite is in alpha alpha stage. It's useless, don't install it.}
14
+
15
+ s.add_development_dependency 'rake', '~> 0.9.2.2'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,11 @@
1
+ require "incite/version"
2
+
3
+ require 'incite/citation'
4
+ require 'incite/source'
5
+ require 'incite/entry'
6
+ require 'incite/note'
7
+ require 'incite/reference'
8
+ require 'incite/inline'
9
+
10
+ module Incite
11
+ end
@@ -0,0 +1,38 @@
1
+ module Incite
2
+ class Citation
3
+ attr_accessor :source
4
+
5
+ def initialize(source)
6
+ self.source = source
7
+ validate_required_attributes!
8
+ end
9
+
10
+ private
11
+
12
+ def formatted_pages
13
+ source.pages.map { |p| p.is_a?(Range) ? "#{p.first}-#{p.last}" : p }.join(", ")
14
+ end
15
+
16
+ def formatted_contributors(type)
17
+ ordered_contributors = source.send(type).sort_by { |c| c.split(" ").last }
18
+ case ordered_contributors.size
19
+ when 2
20
+ ordered_contributors.join(" and ")
21
+ when 3..5
22
+ ordered_contributors.first + " et al."
23
+ else
24
+ ordered_contributors.first
25
+ end.to_s
26
+ end
27
+
28
+ def validate_required_attributes!
29
+ raise ArgumentError, "Source lacks attributes required to construct citation" unless valid_source?
30
+ end
31
+
32
+ def valid_source?
33
+ true
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,9 @@
1
+ module Incite
2
+ class Entry < Incite::Citation
3
+
4
+ def to_html
5
+ "#{formatted_contributors(:authors)}. <em>#{source.title}</em>. #{source.city}: #{source.publisher}, #{source.year}."
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Incite
2
+ class Inline < Incite::Citation
3
+
4
+ def to_html
5
+ "(#{formatted_contributors(:authors)}. #{source.year}, #{formatted_pages})"
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,48 @@
1
+ module Incite
2
+ class Note < Incite::Citation
3
+
4
+ REQUIRED_ATTRS = %w(authors title publisher year pages)
5
+
6
+ def to_html
7
+ relevant_attributes = %w(authors title translators editors volume edition city publisher year pages)
8
+ relevant_attributes.inject("") do |string, attribute|
9
+ string << format_segment_for(attribute)
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def format_segment_for(attribute)
16
+ case attribute
17
+ when "authors"
18
+ formatted_contributors(:authors) + ", "
19
+ when "title"
20
+ "<em>#{source.title}</em>"
21
+ when "translators"
22
+ ", trans. #{formatted_contributors(:translators)}" if source.translators.any?
23
+ when "editors"
24
+ ", ed. #{formatted_contributors(:editors)}" if source.editors.any?
25
+ when "volume"
26
+ ", vol. #{source.volume}" if source.volume
27
+ when "edition"
28
+ ", #{source.edition} ed." if source.edition
29
+ when "city"
30
+ segment = " ("
31
+ segment << "#{source.city}: " if source.city
32
+ segment
33
+ when "publisher"
34
+ "#{source.publisher}, "
35
+ when "year"
36
+ "#{source.year}), "
37
+ when "pages"
38
+ "#{formatted_pages}."
39
+ end.to_s
40
+ end
41
+
42
+ def valid_source?
43
+ source.has_attributes?(REQUIRED_ATTRS)
44
+ end
45
+
46
+ end
47
+ end
48
+
@@ -0,0 +1,9 @@
1
+ module Incite
2
+ class Reference < Incite::Citation
3
+
4
+ def to_html
5
+ "#{formatted_contributors(:authors)}. #{source.year}. <em>#{source.title}</em>. #{source.city}: #{source.publisher}."
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,29 @@
1
+ module Incite
2
+ class Source
3
+
4
+ attr_accessor :title, :authors, :publisher, :city, :year,
5
+ :pages, :editors, :edition, :volume, :translators
6
+
7
+ def initialize(attrs={})
8
+ attrs.each do |attr, value|
9
+ self.send("#{attr}=", value)
10
+ end
11
+ self.pages ||= []
12
+ self.authors ||= []
13
+ self.editors ||= []
14
+ self.translators ||= []
15
+ end
16
+
17
+ def citation(type)
18
+ citation = Incite.const_get(type.to_s.capitalize).new(self).to_html
19
+ end
20
+
21
+ def has_attributes?(attrs)
22
+ !attrs.map do |attr|
23
+ value = send(attr)
24
+ (value.is_a?(Array) && value.any?) || (!value.is_a?(Array) && !value.nil?)
25
+ end.include?(false)
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Incite
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,51 @@
1
+ require "test_helper"
2
+
3
+ unit_tests do
4
+
5
+ test "initializes with source" do
6
+ source = Incite::Source.new
7
+ citation = Incite::Citation.new(source)
8
+ assert_not_nil citation.source
9
+ end
10
+
11
+ test "formats two authors sorting alphabetically joined with 'and'" do
12
+ source = Incite::Source.new(:authors => ["Han Solo", "James Kirk"])
13
+ citation = Incite::Citation.new(source)
14
+ Incite::Citation.publicize_methods do
15
+ assert_equal "James Kirk and Han Solo", citation.formatted_contributors(:authors)
16
+ end
17
+ end
18
+
19
+ test "formats three authors with first and 'et al'" do
20
+ source = Incite::Source.new(:authors => ["Han Solo", "James Kirk", "Cat Stevens"])
21
+ citation = Incite::Citation.new(source)
22
+ Incite::Citation.publicize_methods do
23
+ assert_equal "James Kirk et al.", citation.formatted_contributors(:authors)
24
+ end
25
+ end
26
+
27
+ test "formats one author simply" do
28
+ source = Incite::Source.new(:authors => ["Han Solo"])
29
+ citation = Incite::Citation.new(source)
30
+ Incite::Citation.publicize_methods do
31
+ assert_equal "Han Solo", citation.formatted_contributors(:authors)
32
+ end
33
+ end
34
+
35
+ test "formats array of pages for display in html" do
36
+ source = Incite::Source.new(:pages => [(45..49), 51])
37
+ citation = Incite::Citation.new(source)
38
+ Incite::Citation.publicize_methods do
39
+ assert_equal "45-49, 51", citation.formatted_pages
40
+ end
41
+ end
42
+
43
+ test "returns an empty string when there are no contributors" do
44
+ source = Incite::Source.new
45
+ citation = Incite::Citation.new(source)
46
+ Incite::Citation.publicize_methods do
47
+ assert_equal "", citation.formatted_contributors(:authors)
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,12 @@
1
+ require "test_helper"
2
+
3
+ unit_tests do
4
+
5
+ test "displays html for a works cited entry" do
6
+ source = Incite::Source.new(:authors => ["Han Solo", "James Kirk"], :publisher => "Random House",
7
+ :city => "New York", :year => 1983, :title => "Memoirs from Space", :pages => [(45..49), 51])
8
+ entry = Incite::Entry.new(source)
9
+ assert_equal "James Kirk and Han Solo. <em>Memoirs from Space</em>. New York: Random House, 1983.", entry.to_html
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require "test_helper"
2
+
3
+ unit_tests do
4
+
5
+ test "displays html for an in-text citation" do
6
+ source = Incite::Source.new(:authors => ["Han Solo", "James Kirk"], :publisher => "Random House",
7
+ :city => "New York", :year => 1983, :title => "Memoirs from Space", :pages => [(45..49), 51])
8
+ inline = Incite::Inline.new(source)
9
+ assert_equal "(James Kirk and Han Solo. 1983, 45-49, 51)", inline.to_html
10
+ end
11
+
12
+ end
@@ -0,0 +1,27 @@
1
+ require "test_helper"
2
+
3
+ unit_tests do
4
+
5
+ test "displays html for a footnote or endnote" do
6
+ source = Incite::Source.new(:authors => ["Han Solo", "James Kirk"], :publisher => "Random House",
7
+ :city => "New York", :year => 1983, :title => "Memoirs from Space", :pages => [(45..49), 51],
8
+ :translators => ["Kooky Kookaboora"], :editors => ["Lil Rascal"], :volume => 1, :edition => 2)
9
+ note = Incite::Note.new(source)
10
+ assert_equal "James Kirk and Han Solo, <em>Memoirs from Space</em>, trans. Kooky Kookaboora, ed. Lil Rascal, vol. 1, 2 ed. (New York: Random House, 1983), 45-49, 51.", note.to_html
11
+ end
12
+
13
+ test "omits optional fields without including related formatting and punctuation" do
14
+ source = Incite::Source.new(:authors => ["Han Solo", "James Kirk"], :publisher => "Random House",
15
+ :year => 1983, :title => "Memoirs from Space", :pages => [(45..49), 51])
16
+ note = Incite::Note.new(source)
17
+ assert_equal "James Kirk and Han Solo, <em>Memoirs from Space</em> (Random House, 1983), 45-49, 51.", note.to_html
18
+ end
19
+
20
+ test "raises error if source lacks required attributes" do
21
+ source = Incite::Source.new
22
+ assert_raises ArgumentError do
23
+ Incite::Note.new(source)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,12 @@
1
+ require "test_helper"
2
+
3
+ unit_tests do
4
+
5
+ test "displays html for a reference" do
6
+ source = Incite::Source.new(:authors => ["Han Solo", "James Kirk"], :publisher => "Random House",
7
+ :city => "New York", :year => 1983, :title => "Memoirs from Space", :pages => [(45..49), 51])
8
+ reference = Incite::Reference.new(source)
9
+ assert_equal "James Kirk and Han Solo. 1983. <em>Memoirs from Space</em>. New York: Random House.", reference.to_html
10
+ end
11
+
12
+ end
@@ -0,0 +1,43 @@
1
+ require "test_helper"
2
+
3
+ unit_tests do
4
+
5
+ test "initializes with metadata hash attr" do
6
+ source = Incite::Source.new(:title => "Test title")
7
+ assert_equal("Test title", source.title)
8
+ end
9
+
10
+ test "can be initialized without attrs" do
11
+ assert_nothing_raised do
12
+ source = Incite::Source.new
13
+ end
14
+ end
15
+
16
+ test "outputs html for a given type of citation" do
17
+ source = Incite::Source.new(:authors => ["Han Solo", "James Kirk"], :publisher => "Random House",
18
+ :city => "New York", :year => 1983, :title => "Memoirs from Space", :pages => [(45..49), 51])
19
+ assert_equal "James Kirk and Han Solo. <em>Memoirs from Space</em>. New York: Random House, 1983.", source.citation(:entry)
20
+ end
21
+
22
+ test "correctly interprets lowercase citation types" do
23
+ source = Incite::Source.new
24
+ assert_nothing_raised do
25
+ source.citation(:entry)
26
+ end
27
+ end
28
+
29
+ test "returns true if every element in array is an array with at least one element or not nil" do
30
+ source = Incite::Source.new(:authors => ["Test Author"], :title => "Test Title")
31
+ Incite::Source.publicize_methods do
32
+ assert source.has_attributes?([:authors, :title])
33
+ end
34
+ end
35
+
36
+ test "returns false if every element in array is an array with at least one element or not nil" do
37
+ source = Incite::Source.new(:authors => [], :title => "Test Title")
38
+ Incite::Source.publicize_methods do
39
+ assert !source.has_attributes?([:authors, :title])
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,2 @@
1
+ require "test_helper"
2
+
@@ -0,0 +1,19 @@
1
+ # Require vendor libs
2
+ Dir[File.join(File.dirname(__FILE__), '..', 'vendor', '**', 'lib')].each do |path|
3
+ $: << path
4
+ end
5
+
6
+ require 'incite'
7
+ require 'dust'
8
+
9
+ # For testing private methods
10
+ # Usage: Klass.publicize_methods { Klass.new.private_method_name }
11
+ # http://blog.jayfields.com/2007/11/ruby-testing-private-methods.html
12
+ class Class
13
+ def publicize_methods
14
+ saved_private_instance_methods = self.private_instance_methods
15
+ self.class_eval { public(*saved_private_instance_methods) }
16
+ yield
17
+ self.class_eval { private(*saved_private_instance_methods) }
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: incite
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Thomas Wright
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-24 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 11
29
+ segments:
30
+ - 0
31
+ - 9
32
+ - 2
33
+ - 2
34
+ version: 0.9.2.2
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: Incite is an academic citation library that lets you easily define objects for typical academic sources (eg. books, articles) which can be used to output formatted html for a variety of bibliographical formats (eg. Chicago Manual of Style, MLA). Right now only CMS is supported. Incite is in alpha alpha stage. It's useless, don't install it.
38
+ email:
39
+ - tfwright@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - .travis.yml
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - incite.gemspec
55
+ - lib/incite.rb
56
+ - lib/incite/citation.rb
57
+ - lib/incite/entry.rb
58
+ - lib/incite/inline.rb
59
+ - lib/incite/note.rb
60
+ - lib/incite/reference.rb
61
+ - lib/incite/source.rb
62
+ - lib/incite/version.rb
63
+ - test/incite/citation_test.rb
64
+ - test/incite/entry_test.rb
65
+ - test/incite/inline_test.rb
66
+ - test/incite/note_test.rb
67
+ - test/incite/reference_test.rb
68
+ - test/incite/source_test.rb
69
+ - test/incite_test.rb
70
+ - test/test_helper.rb
71
+ homepage: http://github.com/tfwright/incite
72
+ licenses: []
73
+
74
+ post_install_message:
75
+ rdoc_options: []
76
+
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.18
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Ruby lib for formatting bibliographical data
104
+ test_files:
105
+ - test/incite/citation_test.rb
106
+ - test/incite/entry_test.rb
107
+ - test/incite/inline_test.rb
108
+ - test/incite/note_test.rb
109
+ - test/incite/reference_test.rb
110
+ - test/incite/source_test.rb
111
+ - test/incite_test.rb
112
+ - test/test_helper.rb