Class: Me2Text::Plain

Inherits:
Token
  • Object
show all
Defined in:
lib/me2text/token.rb

Constant Summary

Constants inherited from Token

Token::ESCAPE_CHAR, Token::REGEX_ME2LINK, Token::REGEX_URL

Instance Attribute Summary

Attributes inherited from Token

#text

Instance Method Summary collapse

Methods inherited from Token

join_tokens, #to_s, tokenize, tokenize_keyword, tokenize_me2link, tokenize_plaintext

Constructor Details

#initialize(tv) ⇒ Plain

Returns a new instance of Plain.



188
189
190
# File 'lib/me2text/token.rb', line 188

def initialize(tv)
  @text = tv.gsub(ESCAPE_CHAR, "\"")
end

Instance Method Details

#lengthObject



200
201
202
# File 'lib/me2text/token.rb', line 200

def length
  @text.split(//u).length
end

#to_html(options = {}) ⇒ Object



192
193
194
# File 'lib/me2text/token.rb', line 192

def to_html(options = {})
  htmlize(@text, options)
end

#to_text(options = {}) ⇒ Object



196
197
198
# File 'lib/me2text/token.rb', line 196

def to_text(options = {})
  textize(@text, options)
end

#truncate(nos, format, options = {}) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/me2text/token.rb', line 204

def truncate(nos, format, options = {})
  options = {
    :ellipsis => "…"
  }.merge(options)
  
  val = self.to_s(format, options)

  if (val.length - nos) <= 0 
    val << options[:ellipsis]
  else
    valarr = val.split(//u)
    val = valarr[0...(valarr.length - nos) - 1].to_s
    val << options[:ellipsis]
  end
  
  @text = val 
  
  [val, length]
end