Class: Patento::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/patento/document.rb

Direct Known Subclasses

Patent, Publication

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @number = number.to_s
			if options[:local_path]
@html = Nokogiri::HTML(File.read(options[:local_path]))
			else
  	@html = Nokogiri::HTML(Patento.download_html(number))
			end
end

Instance Attribute Details

#htmlObject

Returns the value of attribute html.



4
5
6
# File 'lib/patento/document.rb', line 4

def html
  @html
end

#numberObject

Returns the value of attribute number.



4
5
6
# File 'lib/patento/document.rb', line 4

def number
  @number
end

Instance Method Details

#abstractObject



22
23
24
# File 'lib/patento/document.rb', line 22

def abstract
  @abstract ||= @html.css('.patent_abstract_text').text
end

#assigneeObject



30
31
32
# File 'lib/patento/document.rb', line 30

def assignee
  @assignee ||= parse_bibdata_links_for_url_match('q=inassignee:')
end

#claimsObject



42
43
44
# File 'lib/patento/document.rb', line 42

def claims
	@claims ||= Claim.parse_claims(@html)
end

#filing_dateObject



38
39
40
# File 'lib/patento/document.rb', line 38

def filing_date
	@filing_date ||= parse_date(:filing)
end

#forward_citationsObject



46
47
48
# File 'lib/patento/document.rb', line 46

def forward_citations
	@forward_citations ||= parse_citations(:forward)
end

#independent_claimsObject



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

#inventorsObject



26
27
28
# File 'lib/patento/document.rb', line 26

def inventors
  @inventors ||= parse_bibdata_links_for_url_match('q=ininventor:')
end


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

#titleObject

Attributes



18
19
20
# File 'lib/patento/document.rb', line 18

def title
  @title ||= @html.css('.main-title').text.split(' - ')[1]
end

#us_classificationsObject



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