verser 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +24 -0
- data/Rakefile +7 -0
- data/lib/verser/reference.rb +43 -0
- data/lib/verser/version.rb +3 -0
- data/lib/verser.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/verser_spec.rb +82 -0
- data/verser.gemspec +22 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
verser (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.2)
|
10
|
+
rspec (2.2.0)
|
11
|
+
rspec-core (~> 2.2)
|
12
|
+
rspec-expectations (~> 2.2)
|
13
|
+
rspec-mocks (~> 2.2)
|
14
|
+
rspec-core (2.2.1)
|
15
|
+
rspec-expectations (2.2.0)
|
16
|
+
diff-lcs (~> 1.1.2)
|
17
|
+
rspec-mocks (2.2.0)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
rspec (~> 2.2.0)
|
24
|
+
verser!
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
|
3
|
+
module Verser
|
4
|
+
class Reference
|
5
|
+
attr_reader :book, :chapter, :from, :to
|
6
|
+
|
7
|
+
def initialize(input)
|
8
|
+
@input = input
|
9
|
+
parse
|
10
|
+
end
|
11
|
+
|
12
|
+
def valid?
|
13
|
+
@valid ||= false
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse
|
17
|
+
@input.downcase.gsub(/\s/,'').match /(\d)?([a-zéèïëô]+)\s*(\d+)([.,:](\d+)-?(\d+)?)?/
|
18
|
+
|
19
|
+
if $1.nil?
|
20
|
+
@book = $2
|
21
|
+
else
|
22
|
+
@book = "#{$1}#{$2}"
|
23
|
+
end
|
24
|
+
|
25
|
+
@chapter = $3.to_i
|
26
|
+
@from = $5.to_i
|
27
|
+
@to = $6.to_i
|
28
|
+
|
29
|
+
validate!
|
30
|
+
end
|
31
|
+
|
32
|
+
def validate!
|
33
|
+
@valid = true
|
34
|
+
@valid = false if @book.nil? or @book.empty?
|
35
|
+
|
36
|
+
unless @to.zero?
|
37
|
+
@valid &&= (@from < @to)
|
38
|
+
end
|
39
|
+
|
40
|
+
@valid
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/verser.rb
ADDED
data/spec/spec_helper.rb
ADDED
data/spec/verser_spec.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding : utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Verser::Reference do
|
6
|
+
it "reads the format : <book>[ ]<chapter>[:.,]<verse>[-<verse>]" do
|
7
|
+
r = Verser::Reference.new 'genèse 1.1-6'
|
8
|
+
r.should be_valid
|
9
|
+
r.book.should == 'genèse'
|
10
|
+
r.chapter.should == 1
|
11
|
+
r.from.should == 1
|
12
|
+
r.to.should == 6
|
13
|
+
|
14
|
+
r = Verser::Reference.new 'genèse 1:1-6'
|
15
|
+
r.should be_valid
|
16
|
+
r.book.should == 'genèse'
|
17
|
+
r.chapter.should == 1
|
18
|
+
r.from.should == 1
|
19
|
+
r.to.should == 6
|
20
|
+
|
21
|
+
r = Verser::Reference.new "genèse\t1,1"
|
22
|
+
r.should be_valid
|
23
|
+
r.book.should == 'genèse'
|
24
|
+
r.chapter.should == 1
|
25
|
+
r.from.should == 1
|
26
|
+
r.to.should == 0
|
27
|
+
|
28
|
+
r = Verser::Reference.new 'genèse1,1'
|
29
|
+
r.should be_valid
|
30
|
+
r.book.should == 'genèse'
|
31
|
+
r.chapter.should == 1
|
32
|
+
r.from.should == 1
|
33
|
+
r.to.should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "reads the format : <number>[ ]<book> <chapter>[:.,]<verse>[-<verse>]" do
|
37
|
+
r = Verser::Reference.new '1 jean 1.1-6'
|
38
|
+
r.should be_valid
|
39
|
+
r.book.should == '1jean'
|
40
|
+
r.chapter.should == 1
|
41
|
+
r.from.should == 1
|
42
|
+
r.to.should == 6
|
43
|
+
|
44
|
+
r = Verser::Reference.new '2rois 1:1-6'
|
45
|
+
r.should be_valid
|
46
|
+
r.book.should == '2rois'
|
47
|
+
r.chapter.should == 1
|
48
|
+
r.from.should == 1
|
49
|
+
r.to.should == 6
|
50
|
+
|
51
|
+
r = Verser::Reference.new '1 Samuel 1,1'
|
52
|
+
r.should be_valid
|
53
|
+
r.book.should == '1samuel'
|
54
|
+
r.chapter.should == 1
|
55
|
+
r.from.should == 1
|
56
|
+
r.to.should == 0
|
57
|
+
end
|
58
|
+
|
59
|
+
it "reads the format : <book>[ ]<chapter>" do
|
60
|
+
r = Verser::Reference.new 'genèse1'
|
61
|
+
r.should be_valid
|
62
|
+
r.book.should == "genèse"
|
63
|
+
r.chapter.should == 1
|
64
|
+
|
65
|
+
r = Verser::Reference.new 'genèse 1'
|
66
|
+
r.should be_valid
|
67
|
+
r.book.should == "genèse"
|
68
|
+
r.chapter.should == 1
|
69
|
+
end
|
70
|
+
|
71
|
+
it "reads the format : <number>[ ]<book> <chapter>" do
|
72
|
+
r = Verser::Reference.new '1samuel 1'
|
73
|
+
r.should be_valid
|
74
|
+
r.book.should == "1samuel"
|
75
|
+
r.chapter.should == 1
|
76
|
+
|
77
|
+
r = Verser::Reference.new '1 samuel 1'
|
78
|
+
r.should be_valid
|
79
|
+
r.book.should == "1samuel"
|
80
|
+
r.chapter.should == 1
|
81
|
+
end
|
82
|
+
end
|
data/verser.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "verser/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "verser"
|
7
|
+
s.version = Verser::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Rawane ZOSSOU"]
|
10
|
+
s.email = ["dev@raw1z.fr"]
|
11
|
+
s.homepage = "http://rubygems.org/gems/verser"
|
12
|
+
s.summary = %q{Verser is a bible verse/chapter reference parser}
|
13
|
+
s.description = %q{Verser is a bible verse/chapter reference parser}
|
14
|
+
|
15
|
+
s.rubyforge_project = "verser"
|
16
|
+
s.add_development_dependency "rspec", "~> 2.2.0"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: verser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Rawane ZOSSOU
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-09 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
version: 2.2.0
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Verser is a bible verse/chapter reference parser
|
36
|
+
email:
|
37
|
+
- dev@raw1z.fr
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- Gemfile.lock
|
48
|
+
- Rakefile
|
49
|
+
- lib/verser.rb
|
50
|
+
- lib/verser/reference.rb
|
51
|
+
- lib/verser/version.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
- spec/verser_spec.rb
|
54
|
+
- verser.gemspec
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://rubygems.org/gems/verser
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: verser
|
83
|
+
rubygems_version: 1.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Verser is a bible verse/chapter reference parser
|
87
|
+
test_files:
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/verser_spec.rb
|