Class: Relaton::Bipm::DataFetcher

Inherits:
Core::DataFetcher
  • Object
show all
Defined in:
lib/relaton/bipm/data_fetcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/relaton/bipm/data_fetcher.rb', line 9

def errors
  @errors
end

#extObject (readonly)

Returns the value of attribute ext.



9
10
11
# File 'lib/relaton/bipm/data_fetcher.rb', line 9

def ext
  @ext
end

#filesObject (readonly)

Returns the value of attribute files.



9
10
11
# File 'lib/relaton/bipm/data_fetcher.rb', line 9

def files
  @files
end

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/relaton/bipm/data_fetcher.rb', line 9

def format
  @format
end

#indexObject (readonly)

Returns the value of attribute index.



9
10
11
# File 'lib/relaton/bipm/data_fetcher.rb', line 9

def index
  @index
end

#outputObject (readonly)

Returns the value of attribute output.



9
10
11
# File 'lib/relaton/bipm/data_fetcher.rb', line 9

def output
  @output
end

Instance Method Details

#fetch(source) ⇒ Object

Fetch bipm-data-outcomes or si-brochure

Parameters:

  • source (String)

    Source name



24
25
26
27
28
29
30
31
32
# File 'lib/relaton/bipm/data_fetcher.rb', line 24

def fetch(source)
  case source
  when "bipm-data-outcomes" then DataOutcomesParser.parse(self)
  when "bipm-si-brochure" then SiBrochureParser.parse(self)
  when "rawdata-bipm-metrologia" then RawdataBipmMetrologia::Fetcher.fetch(self)
  end
  index.save
  report_errors
end

#log_error(msg) ⇒ Object



15
16
17
# File 'lib/relaton/bipm/data_fetcher.rb', line 15

def log_error(msg)
  Util.error msg
end

#to_bibxml(item) ⇒ Object



55
# File 'lib/relaton/bipm/data_fetcher.rb', line 55

def to_bibxml(item) = item.to_rfcxml

#to_xml(item) ⇒ Object



51
# File 'lib/relaton/bipm/data_fetcher.rb', line 51

def to_xml(item) = item.to_xml bibdata: true

#to_yaml(item) ⇒ Object



53
# File 'lib/relaton/bipm/data_fetcher.rb', line 53

def to_yaml(item) = item.to_yaml

#write_file(path, item, warn_duplicate: true) ⇒ Object

Save document to file

Parameters:

  • path (String)

    Path to file

  • item (RelatonBipm::BipmBibliographicItem)

    document to save

  • warn_duplicate (Boolean, nil) (defaults to: true)

    Warn if document already exists



41
42
43
44
45
46
47
48
49
# File 'lib/relaton/bipm/data_fetcher.rb', line 41

def write_file(path, item, warn_duplicate: true)
  content = serialize item
  if @files.include?(path)
    Util.warn "File #{path} already exists" if warn_duplicate
  else
    @files << path
  end
  File.write path, content, encoding: "UTF-8"
end