Module: Tickerizer

Defined in:
lib/tickerizer.rb,
lib/tickerizer/version.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
"1.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.license_idObject

Returns the value of attribute license_id.



23
24
25
# File 'lib/tickerizer.rb', line 23

def license_id
  @license_id
end

Class Method Details

.configurationObject



14
15
16
# File 'lib/tickerizer.rb', line 14

def self.configuration
	@configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



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

def self.configure
	yield(configuration) if block_given?
end

.extract(content) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tickerizer.rb', line 31

def self.extract(content)
	resource = RestClient::Resource.new 'https://api.thomsonreuters.com/permid/calais'
	opts = {
		:content_type => "text/plain",
		:outputformat => "application/json",
		"X-AG-Access-Token" => Tickerizer.configuration.license_id
	}

	resp = resource.post content, opts

	self.process( JSON.parse(resp) )
end

.process(data) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tickerizer.rb', line 44

def self.process(data)
	companies = Array.new

	data.each do |node|
		if node[1]["_type"] == "Company"
			company = {:name => node[1]["name"], :relevance => node[1]["relevance"].to_f}
			company[:ticker] = node[1]["resolutions"][0]["ticker"] if node[1]["resolutions"]

			companies << company
		end
	end

	companies.sort_by{|company| company[:relevance]}.reverse!
end