Class: Relaton::BibdataNew
- Inherits:
-
Object
- Object
- Relaton::BibdataNew
show all
- Defined in:
- lib/relaton/bibdatanew.rb
Class Method Summary
collapse
-
.from_xml(source) ⇒ Object
DOC_NUMBER_REGEX = /([w/]+)s+(d+):?(d*)/ def doc_number docidentifier&.match(DOC_NUMBER_REGEX) ? $2.to_i : 999999 end.
Instance Method Summary
collapse
Constructor Details
#initialize(bibitem) ⇒ BibdataNew
Returns a new instance of BibdataNew.
5
6
7
|
# File 'lib/relaton/bibdatanew.rb', line 5
def initialize(bibitem)
@bibitem = bibitem
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/relaton/bibdatanew.rb', line 9
def method_missing(method, *args)
%r{(?<m>\w+)=$} =~ method
return unless m && %w[xml pdf doc html rxl txt].include?(m)
uri = @bibitem.link.detect { |u| u.type == method }
if uri
uri.content = args[0]
else
@bibitem.link << RelatonBib::TypedUri.new(type: m, content: args[0])
end
end
|
Class Method Details
.from_xml(source) ⇒ Object
DOC_NUMBER_REGEX = /([w/]+)s+(d+):?(d*)/ def doc_number
docidentifier&.match(DOC_NUMBER_REGEX) ? $2.to_i : 999999
end
40
41
42
|
# File 'lib/relaton/bibdatanew.rb', line 40
def self.from_xml(source)
new(Relaton::Cli.parse_xml(source))
end
|
Instance Method Details
#docidentifier ⇒ Object
21
22
23
|
# File 'lib/relaton/bibdatanew.rb', line 21
def docidentifier
@bibitem.docidentifier.first&.id
end
|
#to_h ⇒ Object
54
55
56
|
# File 'lib/relaton/bibdatanew.rb', line 54
def to_h
@bibitem.to_hash
end
|
#to_xml(opts = {}) ⇒ Object
44
45
46
47
48
49
50
51
52
|
# File 'lib/relaton/bibdatanew.rb', line 44
def to_xml(opts = {})
options = { bibdata: true, date_format: :full }.merge opts.select { |k,v| k.is_a? Symbol }
@bibitem.to_xml nil, **options
end
|
#to_yaml ⇒ Object
58
59
60
|
# File 'lib/relaton/bibdatanew.rb', line 58
def to_yaml
to_h.to_yaml
end
|