Class: AfterTheDeadline
- Inherits:
-
Object
- Object
- AfterTheDeadline
- Defined in:
- lib/after_the_deadline.rb
Defined Under Namespace
Constant Summary collapse
- BASE_URI =
'http://service.afterthedeadline.com'- DEFAULT_IGNORE_TYPES =
['Bias Language', 'Cliches', 'Complex Expression', 'Diacritical Marks', 'Double Negatives', 'Hidden Verbs', 'Jargon Language', 'Passive voice', 'Phrases to Avoid', 'Redundant Expression']
- @@custom_dictionary =
[]
- @@ignore_types =
[]
- @@api_key =
nil
Class Method Summary collapse
-
.check(data) ⇒ Object
(also: check_document)
Invoke the checkDocument service with provided text.
-
.metrics(data) ⇒ Object
(also: stats)
Invoke the stats service with provided text.
- .set_api_key(key) ⇒ Object
- .set_custom_dictionary(dict) ⇒ Object
- .set_ignore_types(types) ⇒ Object
Class Method Details
.check(data) ⇒ Object Also known as: check_document
Invoke the checkDocument service with provided text.
Returns list of AfterTheDeadline::Error objects.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/after_the_deadline.rb', line 39 def check(data) results = Crack::XML.parse(perform('/checkDocument', :data => data))['results'] return [] if results.nil? # we have no errors in our data raise "Server returned an error: #{results['message']}" if results['message'] errors = if results['error'].kind_of?(Array) results['error'].map { |e| AfterTheDeadline::Error.new(e) } else [AfterTheDeadline::Error.new(results['error'])] end # Remove any error types we don't care about errors.reject! { |e| @@ignore_types.include?(e.description) } # Remove spelling errors from our custom dictionary errors.reject! { |e| e.type == 'spelling' && @@custom_dictionary.include?(e.string) } return errors end |
.metrics(data) ⇒ Object Also known as: stats
Invoke the stats service with provided text.
Returns AfterTheDeadline::Metrics object.
62 63 64 65 66 |
# File 'lib/after_the_deadline.rb', line 62 def metrics(data) results = Crack::XML.parse(perform('/stats', :data => data))['scores'] return if results.nil? # we have no stats about our data AfterTheDeadline::Metrics.new results['metric'] end |
.set_api_key(key) ⇒ Object
32 33 34 |
# File 'lib/after_the_deadline.rb', line 32 def set_api_key(key) @@api_key = key end |
.set_custom_dictionary(dict) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/after_the_deadline.rb', line 20 def set_custom_dictionary(dict) if dict.kind_of?(Array) @@custom_dictionary = dict elsif dict.kind_of?(String) File.open(dict) { |f| @@custom_dictionary = f.readlines.map &:strip } end end |
.set_ignore_types(types) ⇒ Object
28 29 30 |
# File 'lib/after_the_deadline.rb', line 28 def set_ignore_types(types) @@ignore_types = types if types.kind_of?(Array) end |