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

Author:

  • Alexander Semyonov

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

Class Method Summary collapse

Class Attribute Details

.optionsObject

Returns the value of attribute options.



26
27
28
# File 'lib/als_typograf.rb', line 26

def options
  @options
end

Class Method Details

.[](param) ⇒ Object

Get a global AlsTypograf option

Parameters:

  • param (String, Symbol)

    option name



32
33
34
# File 'lib/als_typograf.rb', line 32

def self.[](param)
  self.options[param.to_sym]
end

.[]=(param, value) ⇒ Object

Set a global AlsTypograf option

Parameters:

  • param (String, Symbol)

    option name

  • value (Numeric, String)

    value for the option



39
40
41
# File 'lib/als_typograf.rb', line 39

def self.[]=(param, value)
  self.options[param.to_sym] = value
end

.debug?Boolean

Returns:

  • (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.default_options!
  self.options = 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

Parameters:

  • exception (Exception)


114
115
116
117
118
119
# File 'lib/als_typograf.rb', line 114

def self.log_exception(exception)
  if debug?
    $stderr.puts exception.message
    $stderr.puts exception.backtrace.join("\n")
  end
end

.max_nobr=(value) ⇒ Object

How many symbols around dash to surround with <nobr> tag

Parameters:

  • value (Numeric, Boolean)

    symbols count



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. &#169;, &nbsp;)



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

Parameters:

  • text (String)

    text to process

  • custom_options (Hash) (defaults to: {})

    the options to process current text with

Options Hash (custom_options):

  • :entity_type (String) — default: NO_ENTITIES

    Type of entities to use in processed text

  • :use_br (String) — default: 1

    Whether or not to use <br />

  • :use_p (String) — default: 1

    Whether or not to surround paras with <p></p>

  • :max_nobr (String) — default: 3

    How many symbols around dash to surround with <nobr> tag

  • :encoding (String) — default: 'UTF-8'

    Encoding of text



109
110
111
# File 'lib/als_typograf.rb', line 109

def self.process(text, custom_options = {})
  Request.process_text(text, custom_options.reverse_merge(options))
end

.use_br=(value) ⇒ Object

Option to replace n with <br />

Parameters:

  • value (Boolean)

    to use <br /> or not



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>

Parameters:

  • value (Boolean)

    to wrap para or not



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. &#169;, &#155;)



54
55
56
# File 'lib/als_typograf.rb', line 54

def self.xml_entities!
  self[:entity_type] = XML_ENTITIES
end