Module: Tickerizer

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

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
"0.0.3"

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
# File 'lib/tickerizer.rb', line 31

def self.extract(content)
	resp = Calais.enlighten(
		:content => content,
		:content_type => :raw,
		:output_format => :json,
		:license_id => Tickerizer.configuration.license_id
	)

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

.process(data) ⇒ Object



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

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