relaton-ogc 1.9.2 → 1.9.3

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: d9ddd36656e221ad7ceb82adf637197b15648451b42fbd78069bc02078082c05
4
- data.tar.gz: 9179d1d896e37f26841c392701c500990eafbfdb1060a4120bb85189014d788e
3
+ metadata.gz: 98e672b4b0d18f3feb9eb6d825d7111e40f3ee97d3886fb452c30c41f4a1dcc0
4
+ data.tar.gz: c9d939a8086f497f95390fd927bb1dee14986bf1b24825a4d0394a3467d9ec3c
5
5
  SHA512:
6
- metadata.gz: 0ab0f2b5ed50fd8f218c92ae1a8589df818f92bb2480fffc450fbe930c16185cc9855d683dc4aafb5d34ad4f808ffd1cc44ba11b19adc6550d62dc029e7c0b11
7
- data.tar.gz: c62733901e8f8790eaaccf90345503fd187bba8e8a08655400fdd77aa508df640ec7a4f11ef1146e41b0e456c538954769cbb4ef2d6eacba3b6b2cac73a70e01
6
+ metadata.gz: de8f29ea78226046ce2138ebacbe2625b0f2b07a6b402d24c3eb5ffb4f9dec2f88062ea185eeb34c04ee363f138664df040342257d04bdbc44a5b5dab3fb2497
7
+ data.tar.gz: d158cfaa42d1ea4cca7bc60463414723d7f78e81a0d8671a9fe647f8d17fb6cf88098d1d46085999a4712f7ffc989a6bf8ad65b20303f949ec1718774e02b3f9
data/README.adoc CHANGED
@@ -39,7 +39,7 @@ require 'relaton_ogc'
39
39
  => true
40
40
 
41
41
  hits = RelatonOgc::OgcBibliography.search("OGC 19-025r1")
42
- => <RelatonOgc::HitCollection:0x007fcc8e085ba8 @ref=OGC 19-025r1 @fetched=false>
42
+ => <RelatonOgc::HitCollection:0x007fcc8e085ba8 @ref=OGC 19-025r1 @fetched=true>
43
43
 
44
44
  tem = hits[0].fetch
45
45
  => #<RelatonOgc::OgcBibliographicItem:0x007fcab3cb4758
data/grammars/ogc.rng CHANGED
@@ -62,6 +62,19 @@
62
62
  </optional>
63
63
  </element>
64
64
  </define>
65
+ <define name="DocumentSubtype">
66
+ <choice>
67
+ <value>conceptual-model</value>
68
+ <value>conceptual-model-and-encoding</value>
69
+ <value>conceptual-model-and-implementation</value>
70
+ <value>encoding</value>
71
+ <value>extension</value>
72
+ <value>implementation</value>
73
+ <value>profile</value>
74
+ <value>profile-with-extension</value>
75
+ <value>general</value>
76
+ </choice>
77
+ </define>
65
78
  </include>
66
79
  <define name="TextElement" combine="choice">
67
80
  <ref name="hi"/>
@@ -79,19 +92,6 @@
79
92
  </zeroOrMore>
80
93
  </element>
81
94
  </define>
82
- <define name="DocumentSubtype">
83
- <choice>
84
- <value>conceptual-model</value>
85
- <value>conceptual-model-and-encoding</value>
86
- <value>conceptual-model-and-implementation</value>
87
- <value>encoding</value>
88
- <value>extension</value>
89
- <value>implementation</value>
90
- <value>profile</value>
91
- <value>profile-with-extension</value>
92
- <value>general</value>
93
- </choice>
94
- </define>
95
95
  <define name="submitters">
96
96
  <element name="submitters">
97
97
  <ref name="Basic-Section"/>
@@ -67,6 +67,8 @@ module RelatonOgc
67
67
  get_data do |etag, json|
68
68
  no_errors = true
69
69
  json.each do |_, hit|
70
+ next if hit["type"] == "CC"
71
+
70
72
  bib = Scrapper.parse_page hit
71
73
  write_document bib
72
74
  rescue StandardError => e
@@ -1,9 +1,20 @@
1
1
  module RelatonOgc
2
2
  class Hit < RelatonBib::Hit
3
+ #
4
+ # <Description>
5
+ #
6
+ # @param [RelatonOgc::OgcBibliographicItem] bibitem
7
+ # @param [RelatonOgc::HitCollection, nil] hitcoll
8
+ #
9
+ def initialize(bibitem, hitcoll = nil)
10
+ super({ id: bibitem.docidentifier[0].id}, hitcoll)
11
+ @fetch = bibitem
12
+ end
13
+
3
14
  # Parse page.
4
15
  # @return [RelatonNist::NistBliographicItem]
5
16
  def fetch
6
- @fetch ||= Scrapper.parse_page @hit
17
+ @fetch # ||= Scrapper.parse_page @hit
7
18
  end
8
19
  end
9
20
  end
@@ -4,63 +4,71 @@ require "fileutils"
4
4
 
5
5
  module RelatonOgc
6
6
  class HitCollection < RelatonBib::HitCollection
7
- include DataFetcher::Utils
7
+ # include DataFetcher::Utils
8
8
 
9
9
  # ENDPOINT = "https://raw.githubusercontent.com/opengeospatial/"\
10
10
  # "NamingAuthority/master/incubation/bibliography/"\
11
11
  # "bibliography.json".freeze
12
- DATADIR = File.expand_path ".relaton/ogc/", Dir.home
13
- DATAFILE = File.expand_path "bibliography.json", DATADIR
12
+ ENDPOINT = "https://raw.githubusercontent.com/relaton/relaton-data-ogc/main/data/".freeze
13
+ # DATADIR = File.expand_path ".relaton/ogc/", Dir.home
14
+ # DATAFILE = File.expand_path "bibliography.json", DATADIR
14
15
  # ETAGFILE = File.expand_path "etag.txt", DATADIR
15
16
 
16
- # @param ref [Strig]
17
+ # @param code [Strig]
17
18
  # @param year [String]
18
19
  # @param opts [Hash]
19
- def initialize(ref, year = nil)
20
+ def initialize(code, year = nil)
20
21
  super
21
- @etagfile = File.expand_path "etag.txt", DATADIR
22
- @array = from_json(ref).sort_by do |hit|
23
- hit.hit["date"] ? Date.parse(hit.hit["date"]) : Date.new
24
- rescue ArgumentError
25
- Date.parse "0000-01-01"
26
- end.reverse
22
+ # @etagfile = File.expand_path "etag.txt", DATADIR
23
+ # @array = from_json(ref).sort_by do |hit|
24
+ # hit.hit["date"] ? Date.parse(hit.hit["date"]) : Date.new
25
+ # rescue ArgumentError
26
+ # Date.parse "0000-01-01"
27
+ # end.reverse
28
+ resp = Faraday.get "#{ENDPOINT}#{code.upcase.gsub(/[\s:.]/, '_')}.yaml"
29
+ @array = case resp.status
30
+ when 200
31
+ bib = OgcBibliographicItem.from_hash YAML.safe_load(resp.body)
32
+ [Hit.new(bib, self)]
33
+ else []
34
+ end
27
35
  end
28
36
 
29
- private
37
+ # private
30
38
 
31
39
  #
32
40
  # Fetch data form json
33
41
  #
34
42
  # @param docid [String]
35
- def from_json(docid, **_opts)
36
- ref = docid.sub(/^OGC\s/, "").strip
37
- return [] if ref.empty?
43
+ # def from_json(docid, **_opts)
44
+ # ref = docid.sub(/^OGC\s/, "").strip
45
+ # return [] if ref.empty?
38
46
 
39
- data.select do |_k, doc|
40
- doc["type"] != "CC" && doc["identifier"].include?(ref)
41
- end.map { |_k, h| Hit.new(h, self) }
42
- end
47
+ # data.select do |_k, doc|
48
+ # doc["type"] != "CC" && doc["identifier"].include?(ref)
49
+ # end.map { |_k, h| Hit.new(h, self) }
50
+ # end
43
51
 
44
52
  #
45
53
  # Fetches json data
46
54
  #
47
55
  # @return [Hash]
48
- def data
49
- ctime = File.ctime DATAFILE if File.exist? DATAFILE
50
- fetch_data if !ctime || ctime.to_date < Date.today
51
- @data ||= JSON.parse File.read(DATAFILE, encoding: "UTF-8")
52
- end
56
+ # def data
57
+ # ctime = File.ctime DATAFILE if File.exist? DATAFILE
58
+ # fetch_data if !ctime || ctime.to_date < Date.today
59
+ # @data ||= JSON.parse File.read(DATAFILE, encoding: "UTF-8")
60
+ # end
53
61
 
54
62
  #
55
63
  # fetch data form server and save it to file.
56
64
  #
57
- def fetch_data
58
- json = get_data
59
- return unless json
65
+ # def fetch_data
66
+ # json = get_data
67
+ # return unless json
60
68
 
61
- FileUtils.mkdir_p DATADIR unless Dir.exist? DATADIR
62
- @data = json
63
- File.write DATAFILE, @data.to_json, encoding: "UTF-8"
64
- end
69
+ # FileUtils.mkdir_p DATADIR unless Dir.exist? DATADIR
70
+ # @data = json
71
+ # File.write DATAFILE, @data.to_json, encoding: "UTF-8"
72
+ # end
65
73
  end
66
74
  end
@@ -4,7 +4,8 @@ module RelatonOgc
4
4
  # @param text [String]
5
5
  # @return [RelatonOgc::HitCollection]
6
6
  def search(text, year = nil, _opts = {})
7
- HitCollection.new text, year
7
+ code = text.sub(/^OGC\s/, "")
8
+ HitCollection.new code, year
8
9
  rescue Faraday::ConnectionFailed
9
10
  raise RelatonBib::RequestError, HitCollection::ENDPOINT
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonOgc
2
- VERSION = "1.9.2".freeze
2
+ VERSION = "1.9.3".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-ogc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.