crown 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.0.8 / 2011-04-03
2
+
3
+ * add check digit for ISBN-10
4
+
1
5
  == 0.0.7 / 2011-04-03
2
6
 
3
7
  * bugfix
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{crown}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["clown"]
@@ -47,5 +47,5 @@ require 'crown/backtype'
47
47
  require 'crown/facebook'
48
48
 
49
49
  module Crown
50
- VERSION = '0.0.6'
50
+ VERSION = '0.0.8'
51
51
  end
@@ -100,10 +100,11 @@ module Crown
100
100
  #
101
101
  # --------------------------------------------------------------- #
102
102
  def get_asin(path, query)
103
- path.split('/').each { |item|
104
- asin = item.match(/[B0123489][A-Z0-9]{9}/)
105
- return asin[0] if (asin != nil)
106
- }
103
+ if (path != nil)
104
+ path.scan(/[B0123489][A-Z0-9]{9}/) { |asin|
105
+ return asin if (asin[0].chr == 'B' || check_digit(asin))
106
+ }
107
+ end
107
108
 
108
109
  if (query != nil)
109
110
  asin = query.match(/[B0123489][A-Z0-9]{9}/)
@@ -112,6 +113,24 @@ module Crown
112
113
 
113
114
  return nil
114
115
  end
116
+
117
+ # --------------------------------------------------------------- #
118
+ #
119
+ # check_digit
120
+ #
121
+ # ISBN-10 のチェックディジット計算して,有効な ISBN-10 の値か
122
+ # どうか判定する.
123
+ #
124
+ # --------------------------------------------------------------- #
125
+ def check_digit(asin)
126
+ sum = 0
127
+ (0..8).each { |i|
128
+ sum += (10 - i) * asin[i].chr.to_i
129
+ }
130
+ check = 11 - (sum % 11)
131
+ check = (check < 10) ? check.to_s : ((check == 10) ? 'X' : '0')
132
+ return check == asin[9].chr
133
+ end
115
134
  end
116
135
 
117
136
  # ------------------------------------------------------------------- #
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crown
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - clown