Class: OpenURL::Patent
- Inherits:
-
ContextObjectEntity
- Object
- ContextObjectEntity
- OpenURL::Patent
- Defined in:
- lib/openurl/metadata_formats/patent.rb
Instance Attribute Summary collapse
-
#inventors ⇒ Object
readonly
Returns the value of attribute inventors.
Attributes inherited from ContextObjectEntity
#abbr, #format, #identifiers, #label, #metadata, #private_data, #reference
Instance Method Summary collapse
- #add_inventor(inventor) ⇒ Object
- #import_xml_metadata(node) ⇒ Object
-
#initialize ⇒ Patent
constructor
A new instance of Patent.
-
#kev(abbr) ⇒ Object
Outputs the entity as a KEV array.
- #method_missing(metadata, value = nil) ⇒ Object
- #remove_inventor(inventor) ⇒ Object
- #serialize_metadata(elem, label) ⇒ Object
- #set_metadata(key, val) ⇒ Object
Methods inherited from ContextObjectEntity
#add_identifier, #delete_identifier, #empty?, #get_metadata, #identifier, new_from_format, normalize_id, #set_format, #set_private_data, #set_reference, #to_hash, #xml, #xml_for_ref_entity
Constructor Details
#initialize ⇒ Patent
Returns a new instance of Patent.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/openurl/metadata_formats/patent.rb', line 15 def initialize super @format = 'patent' @inventors = [OpenURL::Inventor.new] @metadata_keys = ['title','co','cc','kind','applcc','applnumber','number', 'date','applyear','appldate','assignee','pubdate','prioritydate' ] @inventor_keys = ['inv', 'invlast', 'invfirst'] @xml_ns = "info:ofi/fmt:xml:xsd:patent" @kev_ns = "info:ofi/fmt:kev:mtx:patent" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(metadata, value = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/openurl/metadata_formats/patent.rb', line 27 def method_missing(, value=nil) = .to_s.sub(/=$/,'') raise ArgumentError, "#{.to_s} is not a valid #{self.class} metadata field." unless (@inventor_keys+@metadata_keys).index() if .to_s.match(/=$/) self.(, value) if @inventor_keys.index() @inventors[0].instance_variable_set("@#{}", value) end else return self.[] end end |
Instance Attribute Details
#inventors ⇒ Object (readonly)
Returns the value of attribute inventors.
14 15 16 |
# File 'lib/openurl/metadata_formats/patent.rb', line 14 def inventors @inventors end |
Instance Method Details
#add_inventor(inventor) ⇒ Object
48 49 50 51 |
# File 'lib/openurl/metadata_formats/patent.rb', line 48 def add_inventor(inventor) raise ArgumentError, "Argument must be an OpenURL::Author!" unless inventor.is_a?(OpenURL::Inventor) @inventors << inventor end |
#import_xml_metadata(node) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/openurl/metadata_formats/patent.rb', line 76 def (node) mbv = REXML::XPath.first(node, "./ctx:metadata-by-val/ctx:metadata/fmt:#{@format}", {"fmt"=>@xml_ns}) if mbv mbv.to_a.each do |m| self.(m.name(), m.get_text.value) if m.has_text? if m.has_elements? m.to_a.each do | md | self.(md.name(), md.get_text.value) if md.has_text? end end end inv_num = 0 REXML::XPath.each(mbv, "fmt:inventors/fmt:inventor | fmt:inventor/fmt:inv", {"fmt"=>@xml_ns}) do | inventor | empty_node = true if inventor.name == "inventor" inventor.elements.each do | inv_elem | next unless @inventor_keys.index(inv_elem.name) and inv_elem.has_text? empty_node = false @inventors << OpenURL::Inventor.new unless @inventors[inv_num] @inventors[inv_num].instance_variable_set("@#{inv_elem.name}".to_sym, inv_elem.get_text.value) self.(inv_elem.name, inv_elem.get_text.value) if inv_num == 0 end elsif inventor.name.match(/^inv$/) next unless inventor.has_text? empty_node = false @inventors << OpenURL::Inventor.new unless @inventors[inv_num] @inventors[inv_num]["inv"] = inventor.get_text.value self.("inv", inventor.get_text.value) if inv_num == 0 end inv_num += 1 unless empty_node end end end |
#kev(abbr) ⇒ Object
Outputs the entity as a KEV array
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/openurl/metadata_formats/patent.rb', line 112 def kev(abbr) kevs = [] @metadata_keys.each do |key| kevs << "#{abbr}.#{key}="+CGI.escape(@metadata[key]) if @metadata[key] end kevs << "#{abbr}_val_fmt="+CGI.escape(@kev_ns) if @inventors[0] and not @inventors[0].empty? @inventor_keys.each do | ikey | key = ikey key = "inventor" if ikey == "inv" kevs << "#{abbr}.#{key}="+CGI.escape(@inventors[0].ikey) if @inventors[0].ikey end end if @reference["format"] kevs << "#{abbr}_ref_fmt="+CGI.escape(@reference["format"]) kevs << "#{abbr}_ref="+CGI.escape(@reference["location"]) end @identifiers.each do |id| kevs << "#{abbr}_id="+CGI.escape(id) end kevs << "#{abbr}_dat="+CGI.escape(@private_data) if @private_data return kevs end |
#remove_inventor(inventor) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/openurl/metadata_formats/patent.rb', line 53 def remove_inventor(inventor) idx = inventor idx = @inventors.index(inventor) raise ArgumentError unless idx @authors.delete_at(idx) end |
#serialize_metadata(elem, label) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/openurl/metadata_formats/patent.rb', line 60 def (elem, label) = {} = elem.add_element("ctx:metadata") ["format_container"] = .add_element("#{label}:#{@format}") ["format_container"].add_namespace(label, @xml_ns) ["format_container"].add_attribute("xsi:schemaLocation", "#{@xml_ns} http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:#{@format}") @metadata.each do |k,v| next if ['inv', 'invlast', 'invfirst'].index(k) [k] = ["format_container"].add_element("#{label}:#{k}") [k].text = v end ["inventor_container"] = ["format_container"].add_element("#{label}:inventors") @inventors.each do | inventor | inventor.xml(["inventor_container"]) end end |
#set_metadata(key, val) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/openurl/metadata_formats/patent.rb', line 41 def (key, val) @metadata[key] = val if @inventor_keys.index(key) @inventors[0].instance_variable_set("@#{key}", val) end end |