Skip to content

Commit 148c204

Browse files
committed
Decouples completely from Rails. As a consequence, some bits got very, very ugly. Will be refactoring shortly
1 parent 2c00ea2 commit 148c204

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

lib/semantic_extraction.rb

+22-8
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,42 @@
22
require 'nokogiri'
33
require 'extlib'
44
require 'ostruct'
5-
require 'active_support/core_ext/module/attr_accessor_with_default'
65

76
module SemanticExtraction
87

98
class << self
10-
attr_accessor_with_default :preferred_extractor, "alchemy"
11-
attr_accessor_with_default :alchemy_api_key, ""
12-
attr_accessor_with_default :yahoo_api_key, ""
13-
attr_accessor_with_default :valid_extractors, ["yahoo", "alchemy"]
14-
attr_accessor_with_default :requires_api_key, ["yahoo", "alchemy"]
9+
attr_reader :valid_extractors
10+
attr_writer :valid_extractors
11+
12+
attr_reader :requires_api_key
13+
attr_writer :requires_api_key
14+
15+
attr_reader :yahoo_api_key
16+
attr_writer :yahoo_api_key
17+
18+
attr_reader :alchemy_api_key
19+
attr_writer :alchemy_api_key
20+
21+
attr_reader :preferred_extractor
1522
end
1623

24+
self.valid_extractors = ["yahoo", "alchemy"]
25+
26+
self.requires_api_key = ["yahoo", "alchemy"]
27+
1728
# By default, we assume you want to use Alchemy.
1829
# To override, just set SemanticExtraction.preferred_extractor somewhere and define the appropriate api_key.
1930
def self.preferred_extractor=(value)
2031
if self.valid_extractors.include?(value)
21-
@@preferred_extractor = value
32+
@preferred_extractor = value
2233
else
2334
raise NotSupportedExtractor
2435
end
25-
end
36+
end
2637

38+
self.preferred_extractor = "alchemy"
39+
40+
2741
# Screw it. Hard-code time!
2842
require 'semantic_extraction/utility_methods'
2943
require 'semantic_extraction/extractors/yahoo'

test/api_extractor.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module ApiExtractor
55
SemanticExtraction.valid_extractors << "api_extractor"
66
SemanticExtraction.requires_api_key << "api_extractor"
77

8-
SemanticExtraction.module_eval("mattr_accessor :api_extractor_api_key")
8+
SemanticExtraction.module_eval("class << self; attr_reader :api_extractor_api_key end")
9+
SemanticExtraction.module_eval("class << self; attr_writer :api_extractor_api_key end")
910

1011
SemanticExtraction.api_extractor_api_key = "bogus"
1112

0 commit comments

Comments
 (0)