Regenerate gemspec for version 0.1.3
This commit is contained in:
parent
28b6001b0e
commit
c0c41e9396
3
Gemfile
3
Gemfile
|
@ -10,4 +10,7 @@ group :development do
|
|||
gem "bundler", "~> 1.0.0"
|
||||
gem "jeweler", "~> 1.6.4"
|
||||
gem "rcov", ">= 0"
|
||||
gem "rdoc"
|
||||
end
|
||||
|
||||
gem "nokogiri"
|
|
@ -0,0 +1,24 @@
|
|||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
git (1.2.5)
|
||||
jeweler (1.6.4)
|
||||
bundler (~> 1.0)
|
||||
git (>= 1.2.5)
|
||||
rake
|
||||
nokogiri (1.5.0)
|
||||
rake (0.9.2)
|
||||
rcov (0.9.9)
|
||||
rdoc (3.8)
|
||||
shoulda (2.11.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
bundler (~> 1.0.0)
|
||||
jeweler (~> 1.6.4)
|
||||
nokogiri
|
||||
rcov
|
||||
rdoc
|
||||
shoulda
|
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2011 magnolia-fan
|
||||
Copyright (c) 2011 Gregory Eremin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
|
11
README.rdoc
11
README.rdoc
|
@ -1,8 +1,9 @@
|
|||
= fb2
|
||||
== Usage
|
||||
|
||||
Description goes here.
|
||||
require 'fb2'
|
||||
@book = Fb2::parse(open('mybook.fb2'))
|
||||
|
||||
== Contributing to fb2
|
||||
== Contributing
|
||||
|
||||
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
||||
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
||||
|
@ -14,6 +15,4 @@ Description goes here.
|
|||
|
||||
== Copyright
|
||||
|
||||
Copyright (c) 2011 magnolia-fan. See LICENSE.txt for
|
||||
further details.
|
||||
|
||||
Copyright (c) 2011 Gregory Eremin. See LICENSE.txt for further details.
|
||||
|
|
11
Rakefile
11
Rakefile
|
@ -17,10 +17,11 @@ Jeweler::Tasks.new do |gem|
|
|||
gem.name = "fb2"
|
||||
gem.homepage = "http://github.com/magnolia-fan/fb2"
|
||||
gem.license = "MIT"
|
||||
gem.summary = %Q{TODO: one-line summary of your gem}
|
||||
gem.description = %Q{TODO: longer description of your gem}
|
||||
gem.summary = %Q{FB2 util written in ruby}
|
||||
gem.description = %Q{Parses FB2 (FictionBook 2) xml format into nice objects. Uses nokogiri.}
|
||||
gem.email = "magnolia_fan@me.com"
|
||||
gem.authors = ["magnolia-fan"]
|
||||
gem.authors = ["Gregory Eremin"]
|
||||
gem.files += Dir['lib/**/*.rb']
|
||||
# dependencies defined in Gemfile
|
||||
end
|
||||
Jeweler::RubygemsDotOrgTasks.new
|
||||
|
@ -42,8 +43,8 @@ end
|
|||
|
||||
task :default => :test
|
||||
|
||||
require 'rake/rdoctask'
|
||||
Rake::RDocTask.new do |rdoc|
|
||||
require 'rdoc/task'
|
||||
RDoc::Task.new do |rdoc|
|
||||
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
||||
|
||||
rdoc.rdoc_dir = 'rdoc'
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
# Generated by jeweler
|
||||
# DO NOT EDIT THIS FILE DIRECTLY
|
||||
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
||||
# -*- encoding: utf-8 -*-
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = %q{fb2}
|
||||
s.version = "0.1.3"
|
||||
|
||||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = [%q{Gregory Eremin}]
|
||||
s.date = %q{2011-07-17}
|
||||
s.description = %q{Parses FB2 (FictionBook 2) xml format into nice objects. Uses nokogiri.}
|
||||
s.email = %q{magnolia_fan@me.com}
|
||||
s.extra_rdoc_files = [
|
||||
"LICENSE.txt",
|
||||
"README.rdoc"
|
||||
]
|
||||
s.files = [
|
||||
".document",
|
||||
"Gemfile",
|
||||
"Gemfile.lock",
|
||||
"LICENSE.txt",
|
||||
"README.rdoc",
|
||||
"Rakefile",
|
||||
"VERSION",
|
||||
"fb2.gemspec",
|
||||
"lib/fb2.rb",
|
||||
"lib/models/fb2_book.rb",
|
||||
"lib/models/fb2_section.rb",
|
||||
"test/fixtures/sample.fb2",
|
||||
"test/helper.rb",
|
||||
"test/test_fb2.rb"
|
||||
]
|
||||
s.homepage = %q{http://github.com/magnolia-fan/fb2}
|
||||
s.licenses = [%q{MIT}]
|
||||
s.require_paths = [%q{lib}]
|
||||
s.rubygems_version = %q{1.8.5}
|
||||
s.summary = %q{FB2 util written in ruby}
|
||||
|
||||
if s.respond_to? :specification_version then
|
||||
s.specification_version = 3
|
||||
|
||||
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
||||
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
||||
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
||||
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
||||
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
||||
s.add_development_dependency(%q<rcov>, [">= 0"])
|
||||
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
||||
else
|
||||
s.add_dependency(%q<nokogiri>, [">= 0"])
|
||||
s.add_dependency(%q<shoulda>, [">= 0"])
|
||||
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
||||
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
||||
s.add_dependency(%q<rcov>, [">= 0"])
|
||||
s.add_dependency(%q<rdoc>, [">= 0"])
|
||||
end
|
||||
else
|
||||
s.add_dependency(%q<nokogiri>, [">= 0"])
|
||||
s.add_dependency(%q<shoulda>, [">= 0"])
|
||||
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
||||
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
||||
s.add_dependency(%q<rcov>, [">= 0"])
|
||||
s.add_dependency(%q<rdoc>, [">= 0"])
|
||||
end
|
||||
end
|
||||
|
31
lib/fb2.rb
31
lib/fb2.rb
|
@ -0,0 +1,31 @@
|
|||
require 'nokogiri'
|
||||
require 'models/fb2_book'
|
||||
require 'models/fb2_section'
|
||||
|
||||
class Fb2
|
||||
def self.parse data
|
||||
xml = Nokogiri::XML(data)
|
||||
|
||||
# building book
|
||||
description = xml.css('description')
|
||||
book = Fb2Book.new
|
||||
book.title = description.css('title-info > book-title').text
|
||||
book.author_first_name = description.css('title-info > author > first-name').text
|
||||
book.author_last_name = description.css('title-info > author > last-name').text
|
||||
book.annotation = description.css('title-info > annotation > p').text
|
||||
book.genre = description.css('title-info > genre').text
|
||||
book.lang = description.css('title-info > lang').text
|
||||
book.keywords = description.css('title-info > keywords').text.split(', ')
|
||||
book.sections = []
|
||||
|
||||
# building sections
|
||||
xml.css('body > section').each do |s|
|
||||
section = Fb2Section.new
|
||||
section.title = s.css('title > p').text
|
||||
section.contents = s.css('p').map{ |e| e.text }.drop(1)
|
||||
book.sections << section
|
||||
end
|
||||
|
||||
book
|
||||
end
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class Fb2Book
|
||||
attr_accessor :title, :author_first_name, :author_last_name, :annotation, :genre, :lang, :keywords, :sections
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class Fb2Section
|
||||
attr_accessor :title, :contents
|
||||
end
|
|
@ -0,0 +1,59 @@
|
|||
<?xml version="1.0" encoding="utf8"?>
|
||||
<FictionBook xmlns:l="http://www.w3.org/1999/xlink" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.gribuser.ru/xml/fictionbook/2.0">
|
||||
<description>
|
||||
<title-info>
|
||||
<genre>fiction</genre>
|
||||
<author>
|
||||
<first-name>John</first-name>
|
||||
<last-name>Doe</last-name>
|
||||
</author>
|
||||
<book-title>Fiction Book</book-title>
|
||||
<annotation>
|
||||
<p>Hello</p>
|
||||
</annotation>
|
||||
<keywords>john, doe, fiction</keywords>
|
||||
<date value="2011-07-18">18.07.2011</date>
|
||||
<coverpage></coverpage>
|
||||
<lang>en</lang>
|
||||
</title-info>
|
||||
<document-info>
|
||||
<author>
|
||||
<first-name></first-name>
|
||||
<last-name></last-name>
|
||||
<nickname></nickname>
|
||||
</author>
|
||||
<program-used>Fb2 Gem</program-used>
|
||||
<date value="2011-07-18">18.07.2011</date>
|
||||
<src-url></src-url>
|
||||
<src-ocr></src-ocr>
|
||||
<id></id>
|
||||
<version>1.0</version>
|
||||
</document-info>
|
||||
<publish-info>
|
||||
</publish-info>
|
||||
</description>
|
||||
<body>
|
||||
<title>
|
||||
<p>John Doe</p>
|
||||
<empty-line/>
|
||||
<p>Fiction Book</p>
|
||||
</title>
|
||||
<section>
|
||||
<title>
|
||||
<p>Chapter 1</p>
|
||||
</title>
|
||||
<p>Line one of the first chapter</p>
|
||||
<p>Line two of the first chapter</p>
|
||||
<p>Line three of the first chapter</p>
|
||||
</section>
|
||||
<section>
|
||||
<title>
|
||||
<p>Chapter 2</p>
|
||||
</title>
|
||||
<p>Line one of the second chapter</p>
|
||||
<p>Line two of the second chapter</p>
|
||||
<p>Line three of the second chapter</p>
|
||||
<p>Line four of the second chapter</p>
|
||||
</section>
|
||||
</body>
|
||||
</FictionBook>
|
|
@ -1,7 +1,50 @@
|
|||
require 'helper'
|
||||
|
||||
class TestFb2 < Test::Unit::TestCase
|
||||
should "probably rename this file and start testing for real" do
|
||||
flunk "hey buddy, you should probably rename this file and start testing for real"
|
||||
context "parsing" do
|
||||
setup do
|
||||
@book = Fb2::parse(open('test/fixtures/sample.fb2'))
|
||||
end
|
||||
|
||||
should "parse books" do
|
||||
assert_instance_of(Book, @book)
|
||||
end
|
||||
|
||||
should "load correct title" do
|
||||
assert_equal('Fiction Book', @book.title)
|
||||
end
|
||||
|
||||
should "load correct author" do
|
||||
assert_equal('John Doe', [@book.author_first_name, @book.author_last_name].join(' '))
|
||||
end
|
||||
|
||||
should "load correct annotation" do
|
||||
assert_equal('Hello', @book.annotation)
|
||||
end
|
||||
|
||||
should "load correct genre" do
|
||||
assert_equal('fiction', @book.genre)
|
||||
end
|
||||
|
||||
should "load correct language" do
|
||||
assert_equal('en', @book.lang)
|
||||
end
|
||||
|
||||
should "load correct keywords" do
|
||||
assert_equal(['john', 'doe', 'fiction'], @book.keywords)
|
||||
end
|
||||
|
||||
should "load all two chapters" do
|
||||
assert_equal(2, @book.sections.length)
|
||||
end
|
||||
|
||||
should "load correct second chapter's title" do
|
||||
assert_equal('Chapter 2', @book.sections[1].title)
|
||||
end
|
||||
|
||||
should "load all strings in each section" do
|
||||
assert_equal(3, @book.sections[0].contents.length)
|
||||
assert_equal(4, @book.sections[1].contents.length)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue