elibri_onix_dict 0.0.51 → 0.0.60

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
  SHA256:
3
- metadata.gz: e3bc26ba6cef3b38992818f6cf82dbaa03b5d72d01ed1bf4479d78ee816f92ab
4
- data.tar.gz: 502c009c96a7f64bfc5a97ce120d36f0aa83a4ce05b77b3f56b69cc3d71c0caa
3
+ metadata.gz: 8a2607e2bc8cb57fbdb17ff58ee3689905ab3b5a96ab5f504efb460ef77280cd
4
+ data.tar.gz: 56500a5620e953471cdca7fe634da84a070c6353aeb48f927a5043bd9c1eedda
5
5
  SHA512:
6
- metadata.gz: 0f03b433658b0197ee356a9de309e8ad32b11c7c57e136b77e348e080e9d17633e06ba1ba870c964de3727648bfbc4f2d93c81175541dc10c86bafbcbcc7c2d5
7
- data.tar.gz: 59692a9bee0ac48bb840c70f1f29c2452899637c3e9c1dfa271478df71a35d881da2fd8dd95f066137812477932974e56bb2e7a8a7227e00dced6769c94de988
6
+ metadata.gz: 7cd65fd95786a47bddd16a04f850091d3b92f8b0a7f09936e0e08cc6dc1245475bce5650a7ae95369397fa35900890d8254bed2508fb24f722f4f838ed5ebc6c
7
+ data.tar.gz: a95bf930a419e0e4c550dae9cefaa72020ab6e583731f51335e7c87891926b4351ebc783d441c9581874848dc26cede10e1e975ba963fd941f500b18ed38a437
data/Gemfile.lock CHANGED
@@ -1,11 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elibri_onix_dict (0.0.51)
4
+ elibri_onix_dict (0.0.60)
5
+ amatch
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ amatch (0.4.0)
11
+ mize
12
+ tins (~> 1.0)
9
13
  coderay (1.0.6)
10
14
  git (1.2.5)
11
15
  jeweler (1.6.4)
@@ -14,6 +18,10 @@ GEM
14
18
  rake
15
19
  method_source (0.7.1)
16
20
  minitest (3.0.0)
21
+ mize (0.4.0)
22
+ protocol (~> 2.0)
23
+ protocol (2.0.0)
24
+ ruby_parser (~> 3.0)
17
25
  pry (0.9.9.6)
18
26
  coderay (~> 1.0.5)
19
27
  method_source (~> 0.7.1)
@@ -24,8 +32,12 @@ GEM
24
32
  slop (>= 2.4.4, < 3)
25
33
  spoon (~> 0.0)
26
34
  rake (0.9.2.2)
35
+ ruby_parser (3.14.1)
36
+ sexp_processor (~> 4.9)
37
+ sexp_processor (4.13.0)
27
38
  slop (2.4.4)
28
39
  spoon (0.0.1)
40
+ tins (1.22.2)
29
41
 
30
42
  PLATFORMS
31
43
  java
@@ -24,11 +24,11 @@ Gem::Specification.new do |gem|
24
24
 
25
25
  gem.date = %q{2012-04-05}
26
26
 
27
+ gem.add_dependency "amatch"
27
28
  gem.add_development_dependency "pry"
28
29
  gem.add_development_dependency "minitest", ">= 0"
29
30
  gem.add_development_dependency "bundler", ">= 1.0.0"
30
31
  gem.add_development_dependency "jeweler", "~> 1.6.2"
31
- # gem.add_development_dependency "rcov", ">= 0"
32
32
 
33
33
 
34
34
  end
@@ -1,6 +1,7 @@
1
1
 
2
2
  require 'elibri_onix_dict/version'
3
3
  require 'elibri_onix_dict/releases'
4
+ require 'elibri_onix_dict/cover_type'
4
5
  require 'yaml'
5
6
 
6
7
 
@@ -0,0 +1,48 @@
1
+ require 'yaml'
2
+ require 'amatch'
3
+
4
+ module Elibri
5
+ module ONIX
6
+ module Dict
7
+ class CoverType
8
+
9
+ # id to wartość jaka będzie zapisana w polu cover_type_id dla produktu.
10
+ # name to nazwa w obrębie Elibri
11
+ attr_reader :id, :name, :product_form, :product_form_detail
12
+
13
+
14
+ conf = File.expand_path(File.join(File.dirname(__FILE__), "cover_types.yml"))
15
+ ALL = YAML::load_file(conf).sort_by(&:name)
16
+
17
+ HARDBACK = 8
18
+ PLASTIC = 6
19
+ PAPERBACK = 4
20
+
21
+ def self.find(cover_type_id)
22
+ self.all.find {|cover_type| cover_type.id == cover_type_id }
23
+ end
24
+
25
+ def self.determine_cover_type(product_form, product_form_detail)
26
+ matching_cover = all.find { |cover| cover.product_form == product_form && cover.product_form_detail == product_form_detail }
27
+ matching_cover.name if matching_cover
28
+ end
29
+
30
+ # Znajdź w słowniku typ okładki, którego nazwa jest najbardziej podobna do podanego stringu.
31
+ def self.most_similar_to(cover_name)
32
+ if cover_name =~ /karton/
33
+ return all.find { |c| c.name == "twarda" }
34
+ else
35
+ all.sort_by {|cover_type| cover_type.name.downcase.levenshtein_similar(cover_name.downcase) }.last
36
+ end
37
+ end
38
+
39
+
40
+ def self.all
41
+ ALL
42
+ end
43
+
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,47 @@
1
+
2
+ ---
3
+ - !ruby/object:Elibri::ONIX::Dict::CoverType
4
+ id: 1
5
+ name: gąbka
6
+ product_form: BP
7
+ product_form_detail:
8
+ - !ruby/object:Elibri::ONIX::Dict::CoverType
9
+ id: 4
10
+ name: miękka
11
+ product_form: BC
12
+ product_form_detail:
13
+ - !ruby/object:Elibri::ONIX::Dict::CoverType
14
+ id: 5
15
+ name: miękka ze skrzydełkami
16
+ product_form: BC
17
+ product_form_detail: B504
18
+ - !ruby/object:Elibri::ONIX::Dict::CoverType
19
+ id: 6
20
+ name: plastikowa
21
+ product_form: BB
22
+ product_form_detail: B413
23
+ - !ruby/object:Elibri::ONIX::Dict::CoverType
24
+ id: 7
25
+ name: skórzana
26
+ product_form: BG
27
+ product_form_detail:
28
+ - !ruby/object:Elibri::ONIX::Dict::CoverType
29
+ id: 8
30
+ name: twarda
31
+ product_form: BB
32
+ product_form_detail:
33
+ - !ruby/object:Elibri::ONIX::Dict::CoverType
34
+ id: 9
35
+ name: twarda z obwolutą
36
+ product_form: BB
37
+ product_form_detail: B501
38
+ - !ruby/object:Elibri::ONIX::Dict::CoverType
39
+ id: 10
40
+ name: twarda lakierowana
41
+ product_form: BB
42
+ product_form_detail: B415
43
+ - !ruby/object:Elibri::ONIX::Dict::CoverType
44
+ id: 11
45
+ name: zintegrowana
46
+ product_form: BC
47
+ product_form_detail: B412
@@ -1,7 +1,7 @@
1
1
  module Elibri
2
2
  module ONIX
3
3
  module Dict
4
- VERSION = "0.0.51"
4
+ VERSION = "0.0.60"
5
5
  Version = VERSION
6
6
  end
7
7
  end
@@ -6,8 +6,8 @@ require 'helper'
6
6
  describe Elibri::ONIX::Dict::Release_3_0 do
7
7
 
8
8
  it "should be able to build classes on the fly from .yml files" do
9
- assert_equal 12, Elibri::ONIX::Dict::Release_3_0::ProductFormCode::ALL.size
10
- assert_equal 10, Elibri::ONIX::Dict::Release_3_0::ProductFormCode.all_except('BA', 'EA').size
9
+ assert_equal 15, Elibri::ONIX::Dict::Release_3_0::ProductFormCode::ALL.size
10
+ assert_equal 13, Elibri::ONIX::Dict::Release_3_0::ProductFormCode.all_except('BA', 'EA').size
11
11
  assert_equal 'BA', Elibri::ONIX::Dict::Release_3_0::ProductFormCode::BOOK
12
12
  assert_equal '02', Elibri::ONIX::Dict::Release_3_0::EpubUsageStatus::LIMITED
13
13
  assert_equal '01', Elibri::ONIX::Dict::Release_3_0::EpubUsageType::PREVIEW
data/test/helper.rb CHANGED
@@ -7,7 +7,6 @@ rescue Bundler::BundlerError => e
7
7
  $stderr.puts "Run `bundle install` to install missing gems"
8
8
  exit e.status_code
9
9
  end
10
- require 'test/unit'
11
10
  require 'minitest/autorun'
12
11
  require 'pry'
13
12
 
@@ -15,5 +14,3 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
14
  $LOAD_PATH.unshift(File.dirname(__FILE__))
16
15
  require 'elibri_onix_dict'
17
16
 
18
- class Test::Unit::TestCase
19
- end
@@ -0,0 +1,39 @@
1
+ require 'helper'
2
+
3
+
4
+ describe Elibri::ONIX::Dict::CoverType do
5
+
6
+ it "should be able to find most similar dict entry with specified string" do
7
+ assert_equal 'miękka', Elibri::ONIX::Dict::CoverType.most_similar_to('mietka').name
8
+ assert_equal 'miękka ze skrzydełkami', Elibri::ONIX::Dict::CoverType.most_similar_to('skrzydełkowa').name
9
+ assert_equal 'skórzana', Elibri::ONIX::Dict::CoverType.most_similar_to('skórkowa').name
10
+ assert_equal 'twarda', Elibri::ONIX::Dict::CoverType.most_similar_to('karton').name
11
+ end
12
+
13
+ it "should be able to return product_form and product_form_detail" do
14
+ c1 = Elibri::ONIX::Dict::CoverType.find(1)
15
+ assert_equal "gąbka", c1.name
16
+ assert_equal "BP", c1.product_form
17
+ assert_nil c1.product_form_detail
18
+
19
+ c2 = Elibri::ONIX::Dict::CoverType.find(9)
20
+ assert_equal "twarda z obwolutą", c2.name
21
+ assert_equal "BB", c2.product_form
22
+ assert_equal "B501", c2.product_form_detail
23
+ end
24
+
25
+ it "should properly recognize cover types" do
26
+ assert_equal "gąbka", Elibri::ONIX::Dict::CoverType.determine_cover_type("BP", nil)
27
+ assert_equal "miękka", Elibri::ONIX::Dict::CoverType.determine_cover_type("BC", nil)
28
+ assert_equal "miękka ze skrzydełkami", Elibri::ONIX::Dict::CoverType.determine_cover_type("BC", "B504")
29
+ assert_equal "plastikowa", Elibri::ONIX::Dict::CoverType.determine_cover_type("BB", "B413")
30
+ assert_equal "skórzana", Elibri::ONIX::Dict::CoverType.determine_cover_type("BG", nil)
31
+ assert_equal "twarda", Elibri::ONIX::Dict::CoverType.determine_cover_type("BB", nil)
32
+ assert_equal "twarda lakierowana", Elibri::ONIX::Dict::CoverType.determine_cover_type("BB", "B415")
33
+ assert_equal "twarda z obwolutą", Elibri::ONIX::Dict::CoverType.determine_cover_type("BB", "B501")
34
+ assert_equal "zintegrowana", Elibri::ONIX::Dict::CoverType.determine_cover_type("BC", "B412")
35
+
36
+ #nieznana kombinacja
37
+ assert_nil Elibri::ONIX::Dict::CoverType.determine_cover_type("BF", nil)
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elibri_onix_dict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.51
4
+ version: 0.0.60
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Urbanski
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2012-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: amatch
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: pry
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +98,8 @@ files:
84
98
  - Rakefile
85
99
  - elibri_onix_dict.gemspec
86
100
  - lib/elibri_onix_dict.rb
101
+ - lib/elibri_onix_dict/cover_type.rb
102
+ - lib/elibri_onix_dict/cover_types.yml
87
103
  - lib/elibri_onix_dict/onix_3_0/base.rb
88
104
  - lib/elibri_onix_dict/onix_3_0/serialized/AudienceRangePrecision.yml
89
105
  - lib/elibri_onix_dict/onix_3_0/serialized/AudienceRangeQualifier.yml
@@ -138,6 +154,7 @@ files:
138
154
  - test/elibri_onix_dict_release_3_0_test.rb
139
155
  - test/elibri_onix_dict_test.rb
140
156
  - test/helper.rb
157
+ - test/product_cover_type_test.rb
141
158
  homepage: http://github.com/elibri/elibri_onix_dict
142
159
  licenses:
143
160
  - MIT
@@ -166,3 +183,4 @@ test_files:
166
183
  - test/elibri_onix_dict_release_3_0_test.rb
167
184
  - test/elibri_onix_dict_test.rb
168
185
  - test/helper.rb
186
+ - test/product_cover_type_test.rb