class String

Constants

PUNCTUATION

Public Instance Methods

defuse(elements = nil, shadows: []) click to toggle source
# File lib/typogrowth/string.rb, line 35
def defuse elements = nil, shadows: []
  Typogrowth.defuse self, elements || PUNCTUATION, shadows: shadows
end
is_ru?(shadows: []) click to toggle source
# File lib/typogrowth/string.rb, line 31
def is_ru? shadows: []
  Typogrowth.is_ru? self, shadows: shadows
end
psub(pattern, exclusion, replacement) click to toggle source
# File lib/typogrowth/string.rb, line 39
def psub pattern, exclusion, replacement
  delims = self.safe_delimiters
  s = self.dup
  [*exclusion].each { |re|
    re = /#{re}/ unless Regexp === re
    s.gsub!(re) { |m| "#{delims.first}#{Base64.encode64 m}#{delims.last}" }
  }
  s.gsub! pattern, replacement
  s.gsub!(/#{delims.first}(.*?)#{delims.last}/m) { |m|
    Base64.decode64(m).force_encoding('UTF-8')
  }
  s
end
safe_delimiters() click to toggle source

private

# File lib/typogrowth/string.rb, line 55
def safe_delimiters
  delimiters = ['❮', '❯']
  loop do
    break delimiters unless self.match(/#{delimiters.join('|')}/)
    delimiters.map! {|d| d*2}
  end
end
typo(lang: nil, sections: nil, shadows: nil) click to toggle source

Typographyes the string and returns a result See Typogrowth::Parser#parse

# File lib/typogrowth/string.rb, line 12
def typo lang: nil, sections: nil, shadows: nil
  Typogrowth.parse(
    self,
    lang: lang ? lang : is_ru? ? "ru" : I18n.locale,
    shadows: shadows,
    sections: sections
  )
end
typo!(lang: nil, sections: nil, shadows: nil) click to toggle source

Typographyes the string inplace See Typogrowth::Parser#parse!

# File lib/typogrowth/string.rb, line 22
def typo! lang: nil, sections: nil, shadows: nil
  Typogrowth.parse!(
    self,
    lang: lang ? lang : is_ru? ? "ru" : I18n.locale,
    shadows: shadows,
    sections: sections
  )
end