kj 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a7e36e78238c50d8ae07e49691437f92f4f490a
4
- data.tar.gz: 9a7ceef2b2edfd66f5505d96d04a7307eb9fbe78
3
+ metadata.gz: 42a1e80beefbcf7e559c40b5ba4248e677029cbb
4
+ data.tar.gz: c2daad390ff7d1f156524ca772186c4d969f16ca
5
5
  SHA512:
6
- metadata.gz: fde7f9b0e54aafacb78c6f49b77379d39b258d4b2059133bad8d609754dd2138d00d23f8bef11b06097a870ba836c368918cfbb959733ace5592b96540d0ac95
7
- data.tar.gz: 9538435fb181ca6421de82f003dd920669df46a4db2fd6403135a5afbf42faa73e969e718c9b37b6869b98fce44da3766b59eed9fcd0ed10a0822a9df69085cb
6
+ metadata.gz: fec0b308a60ae96bc89c5a0a9794e6aad0d8db73fcee80bc9e05d3bd7219ce520f8f2e870a042f4cada2d78a91fbad438f7e4440462060ab71965c4cd7b4d96c
7
+ data.tar.gz: 7857cef3003d19c876a48ed59ae92336d7a14bf8b14da2e71f0493124ae66492fa945fbb6bbade058f822534003bf4216af7f9669acca5a180ffc5222b70dc14
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/db/kjb.db CHANGED
Binary file
data/kj.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: kj 0.0.7 ruby lib
5
+ # stub: kj 0.0.8 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "kj"
9
- s.version = "0.0.7"
9
+ s.version = "0.0.8"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
@@ -43,8 +43,7 @@ Gem::Specification.new do |s|
43
43
  "spec/verse_spec.rb",
44
44
  "vendor/README.md",
45
45
  "vendor/books.csv",
46
- "vendor/import.rb",
47
- "vendor/parameterize.rb"
46
+ "vendor/import.rb"
48
47
  ]
49
48
  s.homepage = "http://github.com/billguy/kj"
50
49
  s.licenses = ["MIT"]
data/lib/kj.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'kj/db'
1
2
  require 'kj/base'
2
3
  require 'kj/book'
3
4
  require 'kj/chapter'
@@ -1,5 +1,4 @@
1
1
  require "sqlite3"
2
- require 'kj/db'
3
2
 
4
3
  module Kj
5
4
 
@@ -2,7 +2,7 @@ module Kj
2
2
 
3
3
  class Book < Base
4
4
 
5
- attr_accessor :id, :name
5
+ attr_accessor :id, :name, :permalink
6
6
 
7
7
  def initialize(args)
8
8
  args.each do |k,v|
@@ -20,11 +20,11 @@ module Kj
20
20
 
21
21
  def self.from_name_or_number(name_or_number)
22
22
  if name_or_number.is_a?(Integer)
23
- book = Db.query("SELECT id, name FROM books WHERE id = ?", [name_or_number], true)
23
+ book = Db.query("SELECT id, name, permalink FROM books WHERE id = ?", [name_or_number], true)
24
24
  else
25
- book = Db.query("SELECT id, name FROM books WHERE name = ? OR abbreviations LIKE ?", [name_or_number.to_s.downcase, "%#{name_or_number.to_s}%"], true)
25
+ book = Db.query("SELECT id, name, permalink FROM books WHERE name = ? OR abbreviations LIKE ? OR permalink = ?", [name_or_number.to_s.downcase, "%#{name_or_number.to_s}%", name_or_number.to_s], true)
26
26
  end
27
- new(id: book['id'], name: book['name'])
27
+ new(id: book['id'], name: book['name'], permalink: book['permalink'])
28
28
  end
29
29
 
30
30
  def self.from_names_or_numbers(names_or_numbers)
@@ -32,15 +32,15 @@ module Kj
32
32
  numbers = names_or_numbers.uniq.select{|n| n.is_a?(Integer)}
33
33
  names = (names_or_numbers - numbers).uniq.map{|name| name.to_s.downcase}
34
34
  results = []
35
- results << Db.query("SELECT id, name FROM books WHERE id IN (#{numbers.join(',')})") if numbers.any?
36
- names.each{ |name| results << Db.query("SELECT id, name FROM books WHERE abbreviations LIKE ?", ["%#{name.to_s}%"]) }
37
- results.flatten.map!{|book| new(id: book['id'], name: book['name'])}.uniq.sort!{ |a,b| a.id <=> b.id }
35
+ results << Db.query("SELECT id, name, permalink FROM books WHERE id IN (#{numbers.join(',')})") if numbers.any?
36
+ names.each{ |name| results << Db.query("SELECT id, name FROM books WHERE abbreviations LIKE ? OR permalink = ?", ["%#{name.to_s}%", name.to_s]) }
37
+ results.flatten.map!{|book| new(id: book['id'], name: book['name'], permalink: book['permalink'])}.uniq.sort!{ |a,b| a.id <=> b.id }
38
38
  end
39
39
 
40
40
  def self.all
41
41
  @all ||= begin
42
- books = Db.query("SELECT id, name FROM books")
43
- books.map{ |book| new(id: book['id'], name: book['name']) }
42
+ books = Db.query("SELECT id, name, permalink FROM books")
43
+ books.map{ |book| new(id: book['id'], name: book['name'], permalink: book['permalink']) }
44
44
  end
45
45
  end
46
46
 
@@ -1,7 +1,6 @@
1
1
  require 'csv'
2
2
  require "sqlite3"
3
3
  require "pathname"
4
- require_relative "parameterize"
5
4
 
6
5
  path = Pathname(File.absolute_path(__FILE__))
7
6
  db = SQLite3::Database.new(File.join(path.parent.parent.to_s, 'db/kjb.db'))
@@ -14,10 +13,11 @@ csv_text = File.read(File.join(path.parent.to_s, 'books.csv'))
14
13
  csv = CSV.parse(csv_text)
15
14
  csv.each do |row| # build books table
16
15
  book_name = row[0]
16
+ permalink = book_name.downcase.gsub(/[^a-z0-9\-_]+/, '-')
17
17
  abbreviations = row[1].split(',').map{|abb| abb.downcase.gsub(' ', '')}
18
18
  abbreviations << book_name.downcase
19
19
  abbreviations.uniq!
20
- db.execute("INSERT INTO books(name, abbreviations, permalink) VALUES (?, ?, ?)", [book_name, abbreviations.join(','), parameterize(book_name)])
20
+ db.execute("INSERT INTO books(name, abbreviations, permalink) VALUES (?, ?, ?)", [book_name, abbreviations.join(','), permalink])
21
21
  end
22
22
 
23
23
  current_book_id, current_book_name, current_chapter_id, current_chapter_number = nil, nil, nil, nil # import chapters, verses
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - David John
@@ -100,7 +100,6 @@ files:
100
100
  - vendor/README.md
101
101
  - vendor/books.csv
102
102
  - vendor/import.rb
103
- - vendor/parameterize.rb
104
103
  homepage: http://github.com/billguy/kj
105
104
  licenses:
106
105
  - MIT
@@ -1,15 +0,0 @@
1
- # File activesupport/lib/active_support/inflector/transliterate.rb, line 80
2
- def parameterize(string, sep = '-')
3
- # replace accented chars with their ascii equivalents
4
- parameterized_string = string.dup.downcase
5
- # Turn unwanted chars into the separator
6
- parameterized_string.gsub!(/[^a-z0-9\-_]+/, sep)
7
- unless sep.nil? || sep.empty?
8
- re_sep = Regexp.escape(sep)
9
- # No more than one of the separator in a row.
10
- parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
11
- # Remove leading/trailing separator.
12
- parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/, '')
13
- end
14
- parameterized_string
15
- end