ur-sab 0.3 → 0.4

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.
@@ -1,5 +1,7 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.dirname(__FILE__) + '/ur/sab'
2
4
  require File.dirname(__FILE__) + '/ur/sab_search'
3
5
 
4
6
  module UR
5
- end
7
+ end
@@ -1,34 +1,36 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.dirname(__FILE__) + '/sab_codes'
2
4
 
3
5
  module UR
4
6
  class Sab
5
7
  attr_reader :code, :text, :count
6
-
8
+
7
9
  def initialize(code, count = nil)
8
10
  @code = code
9
11
  @text = UR::Sab::translate(code)
10
12
  @count = count
11
13
  end
12
-
14
+
13
15
  def parents
14
16
  sab_parents = []
15
-
17
+
16
18
  if code
17
19
  tmp = ''
18
20
  parts = code.split('')
19
-
21
+
20
22
  parts.pop
21
-
22
- sab_parents = parts.map {|p|
23
+
24
+ sab_parents = parts.map {|p|
23
25
  UR::Sab.new(tmp += p) unless p.match(/(\.|\:)/)
24
26
  }.compact
25
27
  end
26
-
28
+
27
29
  sab_parents
28
30
  end
29
-
31
+
30
32
  def self.translate(code)
31
33
  UR::SAB_CODES.has_key?(code) ? SAB_CODES[code] : false
32
34
  end
33
35
  end
34
- end
36
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module UR
2
4
  SAB_CODES = {
3
5
  'A' => 'Bok- och biblioteksväsen',
@@ -23375,7 +23377,7 @@ module UR
23375
23377
  'Qm-r' => 'Oceanien (Australien, Nya Zeeland, Melanesien, Polynesien, Mikronesien)',
23376
23378
  'Qm-s' => 'Polarländerna',
23377
23379
  'Qz' => 'Särskilda företag',
23378
- 'R' => 'Idrott, lek och spel',
23380
+ 'R' => 'Idrott, lek och spel',
23379
23381
  'Ra' => 'Gymnastik',
23380
23382
  'Rag' => 'Motion',
23381
23383
  'Rah' => 'Bodybuilding',
@@ -25893,4 +25895,4 @@ module UR
25893
25895
  'Äqd' => 'Sydamerika',
25894
25896
  'Är' => 'Oceanien (Australien, Nya Zeeland, Melanesien, Polynesien, Mikronesien)'
25895
25897
  }
25896
- end
25898
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rsolr-ext'
2
4
  require File.dirname(__FILE__) + '/sab'
3
5
 
@@ -7,13 +9,13 @@ module UR
7
9
  if !defined?(SEARCH_SERVICE_URL)
8
10
  SEARCH_SERVICE_URL = 'http://services.ur.se/search'
9
11
  end
10
-
12
+
11
13
  attr_reader :solr, :sab, :subjects
12
-
14
+
13
15
  def initialize(sab_code, options = {})
14
16
  solr = RSolr.connect :url => SEARCH_SERVICE_URL
15
17
  @sab = UR::Sab.new(sab_code) unless sab_code.nil?
16
-
18
+
17
19
  response = solr.find({
18
20
  :indent => 'on',
19
21
  :qt => 'sab',
@@ -22,16 +24,16 @@ module UR
22
24
  'facet.prefix' => sab_code,
23
25
  :q => '*:*',
24
26
  }.merge(options))
25
-
27
+
26
28
  # Expose the Solr response
27
29
  @solr = response
28
-
30
+
29
31
  facet_counts = Hash[*response['facet_counts']['facet_fields']['sab_subjects']]
30
-
32
+
31
33
  sorted_subjects = facet_counts.keys.sort { |l,r| r <=> l }
32
34
  reduced_facet_counts = {}
33
35
 
34
- sorted_subjects.each_index do |j|
36
+ sorted_subjects.each_index do |j|
35
37
  current_code = sorted_subjects[j]
36
38
  next_code = sorted_subjects[j + 1]
37
39
  count = facet_counts[current_code]
@@ -41,12 +43,12 @@ module UR
41
43
  reduced_facet_counts[current_code] = count
42
44
  end
43
45
  else
44
- reduced_facet_counts[current_code] = count
46
+ reduced_facet_counts[current_code] = count
45
47
  end
46
48
  end
47
49
 
48
50
  @subjects = reduced_facet_counts.map { |code, count|
49
- if (@sab.nil? && code.length == 1) ||
51
+ if (@sab.nil? && code.length == 1) ||
50
52
  (!@sab.nil? && code.length < @sab.code.length+2) ||
51
53
  (!@sab.nil? && code.match(/#{@sab.code}\.\d$/)) ||
52
54
  (!@sab.nil? && code.match(/#{@sab.code}\:\w{1,2}$/))
@@ -56,4 +58,4 @@ module UR
56
58
  }.compact.sort { |l,r| l.code <=> r.code }
57
59
  end
58
60
  end
59
- end
61
+ end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ur-sab
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- version: "0.3"
8
+ - 4
9
+ version: "0.4"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Peter Hellberg
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-23 00:00:00 +02:00
17
+ date: 2010-12-16 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency