Skip to content

Commit

Permalink
more work on website type (#14).
Browse files Browse the repository at this point in the history
  • Loading branch information
ethnt committed Apr 5, 2013
1 parent 1369824 commit 5f0a34b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
37 changes: 36 additions & 1 deletion lib/scholar/sources/website.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,46 @@ module Sources
# A normal website.
class Website < Scholar::Source
sequence [

:authors,
:title,
:website,
:editors,
:translators,
:publisher,
:date,
:media,
:accessed,
:url
]

rules do
rule(:authors) {|v| period(v) }

rule(:title) {|v| period(v) }
rule(:title) {|v| quotes(v) }

rule(:website) {|v| italicize(v) }
rule(:website) {|v| period(v) }

rule(:editors) {|v| replace("Ed. #{v}") }
rule(:editors) {|v| period(v) }

rule(:translators) {|v| replace("Trans. #{v}") }
rule(:translators) {|v| period(v) }

rule(:publisher) {|v| comma(v) }

rule(:date) {|v| date(v, "%-d %b. %Y") }
rule(:date) {|v| period(v) }

rule(:media) {|v| replace("Web") }
rule(:media) {|v| period(v) }

rule(:accessed) {|v| date(v, "%-d %b. %Y") }
rule(:accessed) {|v| period(v) }

rule(:url) {|v| carets(v) }
rule(:url) {|v| period(v) }
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/scholar/utilities/formatters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def comma(str)
"#{str.to_s},"
end

# Format a date given a formatted string.
def date(date, str)
date.strftime(str)
end

# Add <em> tags around a String to italicize it.
def italicize(str)
"<em>#{str.to_s}</em>"
Expand Down
41 changes: 41 additions & 0 deletions spec/scholar/sources/website_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,45 @@
require 'spec_helper'

describe Scholar::Sources::Website do
let(:data) do
{
:type => :website,
:title => "The Web is Dead. Long Live the Internet",
:website => "WIRED",
:contributors => [
{
:role => :author,
:first => "Chris",
:last => "Anderson"
},
{
:role => :author,
:first => "Michael",
:last => "Wolff"
},
{
:role => :editor,
:first => "Chuck",
:last => "Squatriglia"
},
{
:role => :translator,
:first => "Linda",
:last => "Zabor"
}
],
:publisher => "WIRED Magazine",
:date => Date.new(2010, 8, 17),
:accessed => Date.new(2013, 4, 5),
:url => "http://www.wired.com/magazine/2010/08/ff_webrip"
}
end

let(:citation) do
"Adams, Douglas N. <em>The Hitchhiker's Guide to the Galaxy</em>. Ed. Peter Guzzardi. Comp. Eion Colfer. Trans. Les Grossman. 1st ed. Vol. 1. London: Random House, 1972. Print. The Hitchhiker's Guide to the Galaxy."
end

let(:c) { Scholar::Citation.new(data) }

it { c.html.should eql citation }
end
6 changes: 6 additions & 0 deletions spec/scholar/utilities/formatters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
it { str.should eql "foo," }
end

describe ".date" do
let(:str) { s.date(Date.new(2013, 4, 5), "%-d %b. %Y") }

it { str.should eql "5 Apr. 2013" }
end

describe ".italicize" do
let(:str) { s.italicize("foo") }

Expand Down

0 comments on commit 5f0a34b

Please sign in to comment.