Class: Patento::Claim

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/patento/claim.rb', line 6

def body
  @body
end

#numberObject

Returns the value of attribute number.



6
7
8
# File 'lib/patento/claim.rb', line 6

def number
  @number
end

#preambleObject

Returns the value of attribute preamble.



6
7
8
# File 'lib/patento/claim.rb', line 6

def preamble
  @preamble
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/patento/claim.rb', line 6

def type
  @type
end

Class Method Details

.extract_all(number, options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/patento/claim.rb', line 22

def self.extract_all(number, options ={})
	if options[:local_path]
		html = Nokogiri::HTML(File.read(options[:local_path]))
	else
    	html = Nokogiri::HTML(Patento.download_html(number))
	end
	
	return parse_claims(html)
	
end

.from_hash(hash) ⇒ Object

Class Methods



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/patento/claim.rb', line 10

def self.from_hash(hash)
	
	claim = Claim.new
	
	claim.number = hash[:number]
	claim.type = hash[:type]
	claim.preamble = hash[:preamble]
	claim.body = hash[:body]
	
	return claim
end

.parse_claims(html) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/patento/claim.rb', line 33

def self.parse_claims(html)
	hash = parse_claims_from_html(html)
	
	formatted_claims = []
	
	hash.each do |hash|
		formatted_claims << Claim.from_hash(hash)
	end
	return formatted_claims
end

.parse_claims_from_html(html) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/patento/claim.rb', line 44

def self.parse_claims_from_html(html)
	elements = html.at_css('#patent_claims_v').children

	claims = []
	index  = -1
	
	
	elements.each do |element|
		next if element.children.empty?

		if element.text.is_preamble?
			index += 1
			claims[index] = {
				number: index + 1,
				type: (element.text.match(/\sclaim\s\d*\s/) ? :dependent : :independent),
				preamble: element.text.gsub(/^\d*\.\s/,''),
				body: []
			}
		else
			claims[index][:body] = parse_dl(element)
		end
	end
	
	return claims
	
end

.parse_dl(element) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/patento/claim.rb', line 71

def self.parse_dl(element)
	elements = []
	
	index = 0
	
	element.children.each do |e|
		unless e.css('dl').empty? # nested elements
			elements[index-1] = [elements[index-1]]
			elements[index-1] << parse_dl(e.css('dl')) # god i hate recursion
		else # plain ol elements
			elements << e.text
			index += 1
		end
		
	end
	elements
end