Class: RelatonBipm::RawdataBipmMetrologia::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb

Constant Summary collapse

DIR =
"rawdata-bipm-metrologia/data/*content/0026-1394"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_fetcher) ⇒ Fetcher

Returns a new instance of Fetcher.

Parameters:



14
15
16
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 14

def initialize(data_fetcher)
  @data_fetcher = WeakRef.new data_fetcher
end

Class Method Details

.fetch(data_fetcher) ⇒ Object

Parameters:



9
10
11
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 9

def self.fetch(data_fetcher)
  new(data_fetcher).fetch
end

Instance Method Details

#docidentifier(id) ⇒ Array<RelatonBib::DocumentIdentifier>

Create docidentifier

Parameters:

  • id (String)

    document identifier

Returns:

  • (Array<RelatonBib::DocumentIdentifier>)

    docidentifier



101
102
103
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 101

def docidentifier(id)
  [RelatonBib::DocumentIdentifier.new(id: id, type: "BIPM", primary: true)]
end

#fetchObject

Fetch documents from rawdata-bipm-metrologia and save to files



21
22
23
24
25
26
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 21

def fetch
  fetch_metrologia
  fetch_volumes
  fetch_issues
  fetch_articles
end

#fetch_articlesObject

Fetch articles from rawdata-bipm-metrologia and save to files



31
32
33
34
35
36
37
38
39
40
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 31

def fetch_articles # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  Dir["#{DIR}/**/*.xml"].each do |path|
    item = ArticleParser.parse path
    file = "#{item.docidentifier.first.id.downcase.tr(' ', '-')}.#{@data_fetcher.ext}"
    out_path = File.join(@data_fetcher.output, file)
    key = Id.new.parse(item.docidentifier.first.id).to_hash
    @data_fetcher.index2.add_or_update key, out_path
    @data_fetcher.write_file out_path, item
  end
end

#fetch_issuesObject

Fetch issues from rawdata-bipm-metrologia and save to files



54
55
56
57
58
59
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 54

def fetch_issues
  Dir["#{DIR}/*/*"].each do |path|
    volume, issue = path.split("/").last(2)
    fetch_metrologia volume, issue
  end
end

#set(volume, issue) ⇒ Object #set(volume) ⇒ Object

Fetch metrologia root document from rawdata-bipm-metrologia and save to a file

Overloads:

  • #set(volume, issue) ⇒ Object

    Parameters:

    • volume (String)

      volume number

    • issue (String)

      issue number

  • #set(volume) ⇒ Object

    Parameters:

    • volume (String)

      volume number



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 70

def fetch_metrologia(*args) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
  id = identifier(*args)
  item = BipmBibliographicItem.new(
    type: "article", formattedref: formattedref(id), docid: docidentifier(id),
    language: ["en"], script: ["Latn"], relation: relation(*args),
    link: typed_uri(*args)
  )
  file = "#{id.downcase.gsub(' ', '-')}.#{@data_fetcher.ext}"
  path = File.join(@data_fetcher.output, file)
  @data_fetcher.index2.add_or_update Id.new.parse(id).to_hash, path
  @data_fetcher.write_file path, item
end

#fetch_volumesObject

Fetch volumes from rawdata-bipm-metrologia and save to files



45
46
47
48
49
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 45

def fetch_volumes
  Dir["#{DIR}/*"].map { |path| path.split("/").last }.uniq.each do |volume|
    fetch_metrologia volume
  end
end

#formattedref(id) ⇒ RelatonBib::FormattedRef

Create formattedref

Parameters:

  • id (String)

    document identifier

Returns:

  • (RelatonBib::FormattedRef)

    formattedref



90
91
92
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 90

def formattedref(id)
  RelatonBib::FormattedRef.new content: id, language: "en", script: "Latn"
end

#id_parts(*args) ⇒ Object



124
125
126
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 124

def id_parts(*args)
  args.map { |p| p.match(/[^_]+$/).to_s }
end

#set(volume, issue, article) ⇒ String #set(volume, issue) ⇒ String #set(volume) ⇒ String

Create identifier

Overloads:

  • #set(volume, issue, article) ⇒ String

    Parameters:

    • volume (String)

      volume number

    • issue (String)

      issue number

    • article (String)

      article number

  • #set(volume, issue) ⇒ String

    Parameters:

    • volume (String)

      volume number

    • issue (String)

      issue number

  • #set(volume) ⇒ String

    Parameters:

    • volume (String)

      volume number

Returns:

  • (String)

    document identifier



120
121
122
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 120

def identifier(*args)
  ["Metrologia", *id_parts(*args)].join(" ")
end


162
163
164
165
166
167
168
169
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 162

def link(*args)
  params = id_parts(*args).join("/")
  case args.size
  when 0 then "https://iopscience.iop.org/journal/0026-1394"
  when 1 then "https://iopscience.iop.org/volume/0026-1394/#{params}"
  when 2 then "https://iopscience.iop.org/issue/0026-1394/#{params}"
  end
end

#rel_bibitem(id) ⇒ RelatonBipm::BipmBibliographicItem

Create relation bibitem

Parameters:

  • id (String)

    document identifier

Returns:



152
153
154
155
156
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 152

def rel_bibitem(id)
  BipmBibliographicItem.new(
    formattedref: formattedref(id), docid: docidentifier(id),
  )
end

#relation(*args) ⇒ Array<RelatonBib::DocumentRelation>

Fetch relations

Returns:

  • (Array<RelatonBib::DocumentRelation>)

    relations

See Also:



135
136
137
138
139
140
141
142
143
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 135

def relation(*args)
  dir = [DIR, *args].join("/")
  ids = Set.new
  Dir["#{dir}/*"].each do |path|
    part = path.split("/").last
    ids << identifier(*args, part)
  end
  ids.map { |id| RelatonBib::DocumentRelation.new(type: "partOf", bibitem: rel_bibitem(id)) }
end

#typed_uri(*args) ⇒ Object



158
159
160
# File 'lib/relaton_bipm/rawdata_bipm_metrologia/fetcher.rb', line 158

def typed_uri(*args)
  [RelatonBib::TypedUri.new(type: "src", content: link(*args))]
end