Class: Relaton::Render::Ietf::Parse
- Inherits:
-
Parse
- Object
- Parse
- Relaton::Render::Ietf::Parse
- Defined in:
- lib/relaton/render/parse.rb
Instance Method Summary collapse
- #abstract(doc) ⇒ Object
- #authoritative_identifier(doc) ⇒ Object
-
#creatornames1(doc) ⇒ Object
return authors and editors together.
-
#creatornames_roles_allowed ⇒ Object
allow publisher for standards.
-
#date(doc, host) ⇒ Object
not just year-only.
- #extract(doc) ⇒ Object
- #extract_orgabbrev(org) ⇒ Object
- #extract_personname(person) ⇒ Object
- #extractname(contributor) ⇒ Object
- #home_standard(_doc, pubs) ⇒ Object
- #included_xml2hash(doc) ⇒ Object
-
#initialize(options) ⇒ Parse
constructor
A new instance of Parse.
- #keyword1(kw) ⇒ Object
- #keywords(doc) ⇒ Object
- #parse_single_bibitem(doc) ⇒ Object
- #series(doc) ⇒ Object
- #series_xml2hash1(series, doc) ⇒ Object
- #simple_or_host_xml2hash(doc, host) ⇒ Object
- #simple_xml2hash(doc) ⇒ Object
- #stream(doc) ⇒ Object
- #uris(doc) ⇒ Object
Constructor Details
Instance Method Details
#abstract(doc) ⇒ Object
55 56 57 |
# File 'lib/relaton/render/parse.rb', line 55 def abstract(doc) Array(doc.abstract).map { |a| content(a) }.join end |
#authoritative_identifier(doc) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'lib/relaton/render/parse.rb', line 104 def (doc) ret = super bcp = Array(doc.series).detect do |s| %w(BCP STD).include?(Array(s.title).first&.content) end bcp and ret.unshift("BCP\u00A0#{bcp.number}") ret.reject { |x| /(rfc-anchor|Internet-Draft)/.match?(x) } .map { |x| x.gsub(/<\/?esc>/, "").tr(" ", "\u00A0") } end |
#creatornames1(doc) ⇒ Object
return authors and editors together
94 95 96 97 98 99 100 101 102 |
# File 'lib/relaton/render/parse.rb', line 94 def creatornames1(doc) return [] if doc.nil? add1 = pick_contributor(doc, "author") || [] add2 = pick_contributor(doc, "editor") || [] cr = add1 + add2 cr.empty? or return cr super end |
#creatornames_roles_allowed ⇒ Object
allow publisher for standards
25 26 27 28 |
# File 'lib/relaton/render/parse.rb', line 25 def creatornames_roles_allowed %w(author performer adapter translator editor publisher distributor authorizer) end |
#date(doc, host) ⇒ Object
not just year-only
87 88 89 90 91 |
# File 'lib/relaton/render/parse.rb', line 87 def date(doc, host) ret = date1(Array(doc.date)) host and ret ||= date1(Array(host.date)) datepick(ret) end |
#extract(doc) ⇒ Object
131 132 133 |
# File 'lib/relaton/render/parse.rb', line 131 def extract(doc) super.merge(included_xml2hash(doc)) end |
#extract_orgabbrev(org) ⇒ Object
71 72 73 |
# File 'lib/relaton/render/parse.rb', line 71 def extract_orgabbrev(org) content(org.abbreviation) end |
#extract_personname(person) ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/relaton/render/parse.rb', line 75 def extract_personname(person) surname = person.name.surname completename = person.name.completename given, middle, initials = given_and_middle_name(person) { surname: content(surname), completename: content(completename), given: given, middle: middle, initials: initials }.compact end |
#extractname(contributor) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/relaton/render/parse.rb', line 59 def extractname(contributor) org = contributor.organization person = contributor.person if org return { nonpersonal: extract_orgname(org), nonpersonalabbrev: extract_orgabbrev(org) } end return extract_personname(person) if person nil end |
#home_standard(_doc, pubs) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/relaton/render/parse.rb', line 17 def home_standard(_doc, pubs) pubs&.any? do |r| ["Internet Engineering Task Force", "IETF", "RFC Publisher"] .include?(r[:nonpersonal]) end end |
#included_xml2hash(doc) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/relaton/render/parse.rb', line 135 def included_xml2hash(doc) r = Array(doc.relation).select { |x| x.type == "includes" }.map do |x| parse_single_bibitem(x.bibitem) end r.empty? and return {} { included: r } end |
#keyword1(kw) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/relaton/render/parse.rb', line 47 def keyword1(kw) v = Array(kw.vocab).first v and return content(v) t = Array(kw.taxon).first t and return content(t) kw.vocabid&.term end |
#keywords(doc) ⇒ Object
43 44 45 |
# File 'lib/relaton/render/parse.rb', line 43 def keywords(doc) Array(doc.keyword).map { |u| keyword1(u) }.compact end |
#parse_single_bibitem(doc) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/relaton/render/parse.rb', line 143 def parse_single_bibitem(doc) extract(doc) # enhance_data(data, r.template_raw) # data_liquid = @fieldsklass.new(renderer: self) # .compound_fields_format(data) end |
#series(doc) ⇒ Object
118 119 120 121 122 123 |
# File 'lib/relaton/render/parse.rb', line 118 def series(doc) a = Array(doc.series).reject { |s| s.type == "stream" } a.empty? and return nil a.detect { |s| s.type == "main" } || a.detect { |s| s.type.nil? } || a.first end |
#series_xml2hash1(series, doc) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/relaton/render/parse.rb', line 30 def series_xml2hash1(series, doc) ret = super plain_title = ret[:series_title]&.gsub(/<\/?esc>/, "") %w(BCP RFC I-D. Internet-Draft).include?(plain_title) and return {} ret end |
#simple_or_host_xml2hash(doc, host) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/relaton/render/parse.rb', line 10 def simple_or_host_xml2hash(doc, host) ret = super ret.merge(home_standard: home_standard(doc, ret[:publisher_raw]), uris: uris(doc), keywords: keywords(doc), abstract: abstract(doc)) end |
#simple_xml2hash(doc) ⇒ Object
114 115 116 |
# File 'lib/relaton/render/parse.rb', line 114 def simple_xml2hash(doc) super.merge(stream: stream(doc)) end |
#stream(doc) ⇒ Object
125 126 127 128 129 |
# File 'lib/relaton/render/parse.rb', line 125 def stream(doc) a = Array(doc.series).detect { |s| s.type == "stream" } or return nil Array(a.title).first&.content == "Legacy" and return nil series_title(a, doc) end |
#uris(doc) ⇒ Object
37 38 39 40 41 |
# File 'lib/relaton/render/parse.rb', line 37 def uris(doc) Array(doc.source).map do |u| { content: u.content.to_s.strip, type: u.type } end end |