Module: AlsTypograf
- Defined in:
- lib/als_typograf.rb,
lib/als_typograf/request.rb,
lib/als_typograf/version.rb
Overview
Ruby client for ArtLebedevStudio.RemoteTypograf web-service
Defined Under Namespace
Modules: Request
Constant Summary collapse
- HTML_ENTITIES =
1
- XML_ENTITIES =
2
- NO_ENTITIES =
3
- MIXED_ENTITIES =
4
- DEFAULT_OPTIONS =
{ entity_type: NO_ENTITIES, use_br: true, use_p: true, max_nobr: 3, encoding: 'UTF-8', debug: false }
- VALID_OPTIONS =
DEFAULT_OPTIONS.keys.join('|')
- VERSION =
'0.3.0'
Class Attribute Summary collapse
-
.options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.[](param) ⇒ Object
Get a global AlsTypograf option.
-
.[]=(param, value) ⇒ Object
Set a global AlsTypograf option.
- .debug? ⇒ Boolean
-
.default_options! ⇒ Object
Reset default options.
-
.html_entities! ⇒ Object
Set option #entity_type to HTML (e. g. , —).
- .log_exception(exception) ⇒ Object
-
.max_nobr=(value) ⇒ Object
How many symbols around dash to surround with <nobr> tag.
- .method_missing(method_name, *args) ⇒ Object
-
.mixed_entities! ⇒ Object
Set option #entity_type to mixed (e. g. ©, ).
-
.no_entities! ⇒ Object
Set option #entity_type to nothing (e. g. —, ©, ×).
-
.process(text, custom_options = {}) ⇒ Object
Process text with Typograf web-service.
-
.use_br=(value) ⇒ Object
Option to replace n with <br />.
-
.use_p=(value) ⇒ Object
Option to wrap paragraphs with <p></p>.
-
.xml_entities! ⇒ Object
Set option #entity_type to XML (e. g. ©, ›).
Class Attribute Details
.options ⇒ Object
Returns the value of attribute options.
26 27 28 |
# File 'lib/als_typograf.rb', line 26 def @options end |
Class Method Details
.[](param) ⇒ Object
Get a global AlsTypograf option
32 33 34 |
# File 'lib/als_typograf.rb', line 32 def self.[](param) self.[param.to_sym] end |
.[]=(param, value) ⇒ Object
Set a global AlsTypograf option
39 40 41 |
# File 'lib/als_typograf.rb', line 39 def self.[]=(param, value) self.[param.to_sym] = value end |
.debug? ⇒ Boolean
86 87 88 |
# File 'lib/als_typograf.rb', line 86 def self.debug? !!self[:debug] end |
.default_options! ⇒ Object
Reset default options
44 45 46 |
# File 'lib/als_typograf.rb', line 44 def self. self. = DEFAULT_OPTIONS.dup end |
.html_entities! ⇒ Object
Set option #entity_type to HTML (e. g. , —)
49 50 51 |
# File 'lib/als_typograf.rb', line 49 def self.html_entities! self[:entity_type] = HTML_ENTITIES end |
.log_exception(exception) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/als_typograf.rb', line 114 def self.log_exception(exception) if debug? $stderr.puts exception. $stderr.puts exception.backtrace.join("\n") end end |
.max_nobr=(value) ⇒ Object
How many symbols around dash to surround with <nobr> tag
82 83 84 |
# File 'lib/als_typograf.rb', line 82 def self.max_nobr=(value) self[:max_nobr] = value ? value : 0 end |
.method_missing(method_name, *args) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/als_typograf.rb', line 90 def self.method_missing(method_name, *args) case method_name.to_s when /^(#{VALID_OPTIONS})=$/ self[$1.to_sym] = args.first when /^(#{VALID_OPTIONS})$/ self[method_name.to_sym] else super end end |
.mixed_entities! ⇒ Object
Set option #entity_type to mixed (e. g. ©, )
64 65 66 |
# File 'lib/als_typograf.rb', line 64 def self.mixed_entities! self[:entity_type] = MIXED_ENTITIES end |
.no_entities! ⇒ Object
Set option #entity_type to nothing (e. g. —, ©, ×)
59 60 61 |
# File 'lib/als_typograf.rb', line 59 def self.no_entities! self[:entity_type] = NO_ENTITIES end |
.process(text, custom_options = {}) ⇒ Object
Process text with Typograf web-service
109 110 111 |
# File 'lib/als_typograf.rb', line 109 def self.process(text, = {}) Request.process_text(text, .reverse_merge()) end |
.use_br=(value) ⇒ Object
Option to replace n with <br />
70 71 72 |
# File 'lib/als_typograf.rb', line 70 def self.use_br=(value) self[:use_br] = value end |
.use_p=(value) ⇒ Object
Option to wrap paragraphs with <p></p>
76 77 78 |
# File 'lib/als_typograf.rb', line 76 def self.use_p=(value) self[:use_p] = value end |
.xml_entities! ⇒ Object
Set option #entity_type to XML (e. g. ©, ›)
54 55 56 |
# File 'lib/als_typograf.rb', line 54 def self.xml_entities! self[:entity_type] = XML_ENTITIES end |