Class: StandaloneTypograf::Quotes::Processor
- Inherits:
-
Object
- Object
- StandaloneTypograf::Quotes::Processor
- Defined in:
- lib/standalone_typograf/quotes.rb
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#tarr ⇒ Object
readonly
Returns the value of attribute tarr.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(text, mode) ⇒ Processor
constructor
A new instance of Processor.
- #lock ⇒ Object
Constructor Details
#initialize(text, mode) ⇒ Processor
Returns a new instance of Processor.
36 37 38 39 40 41 42 43 |
# File 'lib/standalone_typograf/quotes.rb', line 36 def initialize(text, mode) @text = text @mode = mode # `tarr` means <b>text array</b> # this is because replaced item may contain more than 1 char (like `«`) # so replaced value will be placed into the one array cell. @tarr = text.split(//) end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
28 29 30 |
# File 'lib/standalone_typograf/quotes.rb', line 28 def mode @mode end |
#tarr ⇒ Object (readonly)
Returns the value of attribute tarr.
28 29 30 |
# File 'lib/standalone_typograf/quotes.rb', line 28 def tarr @tarr end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
28 29 30 |
# File 'lib/standalone_typograf/quotes.rb', line 28 def text @text end |
Class Method Details
.compile(text, mode) ⇒ Object
30 31 32 33 34 |
# File 'lib/standalone_typograf/quotes.rb', line 30 def self.compile(text, mode) compiler = self.new(text, mode) compiler.compile text = compiler.tarr.join() end |
Instance Method Details
#compile ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/standalone_typograf/quotes.rb', line 49 def compile tarr.each_with_index do |symbol, index| next unless symbol == Q # == Outer if outside? && open_quote?(index) tarr[index] = CHARS[:outer_left][mode] outer_open_lock! next end if inside? && !lock[:inner_open] && close_quote?(index) tarr[index] = CHARS[:outer_right][mode] outer_open_unlock! next end # == Inner if inside? && !lock[:inner_open] && open_quote?(index) tarr[index] = CHARS[:inner_left][mode] inner_open_lock! next end if inside? && lock[:inner_open] && close_quote?(index) tarr[index] = CHARS[:inner_right][mode] inner_open_unlock! next end end end |
#lock ⇒ Object
45 46 47 |
# File 'lib/standalone_typograf/quotes.rb', line 45 def lock @lock ||= LOCK.deep_dup end |