Class: Patento::Document
- Inherits:
-
Object
- Object
- Patento::Document
- Defined in:
- lib/patento/document.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#html ⇒ Object
Returns the value of attribute html.
-
#number ⇒ Object
Returns the value of attribute number.
Instance Method Summary collapse
- #abstract ⇒ Object
- #assignee ⇒ Object
- #claims ⇒ Object
- #filing_date ⇒ Object
- #forward_citations ⇒ Object
- #independent_claims ⇒ Object
-
#initialize(number, options = {}) ⇒ Document
constructor
Note: attributes are lazily evaluated.
- #inventors ⇒ Object
- #parse_bibdata_links_for_url_match(pattern) ⇒ Object
-
#parse_citations(type) ⇒ Object
Helpers.
- #parse_date(type) ⇒ Object
-
#title ⇒ Object
Attributes.
- #us_classifications ⇒ Object
Constructor Details
#initialize(number, options = {}) ⇒ Document
Note: attributes are lazily evaluated
7 8 9 10 11 12 13 14 |
# File 'lib/patento/document.rb', line 7 def initialize(number, = {}) @number = number.to_s if [:local_path] @html = Nokogiri::HTML(File.read([:local_path])) else @html = Nokogiri::HTML(Patento.download_html(number)) end end |
Instance Attribute Details
#html ⇒ Object
Returns the value of attribute html.
4 5 6 |
# File 'lib/patento/document.rb', line 4 def html @html end |
#number ⇒ Object
Returns the value of attribute number.
4 5 6 |
# File 'lib/patento/document.rb', line 4 def number @number end |
Instance Method Details
#abstract ⇒ Object
22 23 24 |
# File 'lib/patento/document.rb', line 22 def abstract @abstract ||= @html.css('.patent_abstract_text').text end |
#assignee ⇒ Object
30 31 32 |
# File 'lib/patento/document.rb', line 30 def assignee @assignee ||= parse_bibdata_links_for_url_match('q=inassignee:') end |
#claims ⇒ Object
42 43 44 |
# File 'lib/patento/document.rb', line 42 def claims @claims ||= Claim.parse_claims(@html) end |
#filing_date ⇒ Object
38 39 40 |
# File 'lib/patento/document.rb', line 38 def filing_date @filing_date ||= parse_date(:filing) end |
#forward_citations ⇒ Object
46 47 48 |
# File 'lib/patento/document.rb', line 46 def forward_citations @forward_citations ||= parse_citations(:forward) end |
#independent_claims ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/patento/document.rb', line 50 def independent_claims independent_claims = [] claims.each do |c| if c[:type] == :independent independent_claims << c end end return independent_claims end |
#inventors ⇒ Object
26 27 28 |
# File 'lib/patento/document.rb', line 26 def inventors @inventors ||= parse_bibdata_links_for_url_match('q=ininventor:') end |
#parse_bibdata_links_for_url_match(pattern) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/patento/document.rb', line 86 def parse_bibdata_links_for_url_match(pattern) @matches = @html.css('#summarytable div.patent_bibdata a').to_a @matches.collect! { |link| link.text if link.attr('href').match(pattern) } @matches.compact! @matches = @matches.first if @matches.count == 1 return @matches end |
#parse_citations(type) ⇒ Object
Helpers
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/patento/document.rb', line 62 def parse_citations(type) container = (type == :backward ? '#patent_citations_v tr' : '#patent_referenced_by_v tr') trs = @html.css(container) trs.shift citations = [] trs.each do |row| citations << { number: row.css('td')[0].css('a').text.gsub(/^US/, ''), filing: Date.parse(row.css('td')[1].text), issue: Date.parse(row.css('td')[2].text), assignee: row.css('td')[3].text, title: row.css('td')[4].text } end return citations end |
#parse_date(type) ⇒ Object
80 81 82 83 84 |
# File 'lib/patento/document.rb', line 80 def parse_date(type) nodes = @html.css('#metadata_v .patent_bibdata p').children index = (type == :filing ? 4 : 7) Date.parse(nodes[index].text) end |
#title ⇒ Object
Attributes
18 19 20 |
# File 'lib/patento/document.rb', line 18 def title @title ||= @html.css('.main-title').text.split(' - ')[1] end |
#us_classifications ⇒ Object
34 35 36 |
# File 'lib/patento/document.rb', line 34 def us_classifications @us_classifications ||= parse_bibdata_links_for_url_match('q=http://www.uspto.gov/web/patents/classification/') end |