Class: Me2Text::Link
Constant Summary
Constants inherited from Token
Token::ESCAPE_CHAR, Token::REGEX_ME2LINK, Token::REGEX_URL
Instance Attribute Summary collapse
-
#include_ws ⇒ Object
Returns the value of attribute include_ws.
-
#link ⇒ Object
Returns the value of attribute link.
Attributes inherited from Token
Instance Method Summary collapse
-
#initialize(label, link, include_ws = false) ⇒ Link
constructor
A new instance of Link.
- #length(options = {}) ⇒ Object
- #to_html(options = {}) ⇒ Object
- #to_label(format, options = {}) ⇒ Object
- #to_text(options = {}) ⇒ Object
- #truncate(nos, format, options = {}) ⇒ Object
Methods inherited from Token
join_tokens, #to_s, tokenize, tokenize_keyword, tokenize_me2link, tokenize_plaintext
Constructor Details
#initialize(label, link, include_ws = false) ⇒ Link
Returns a new instance of Link.
229 230 231 232 233 |
# File 'lib/me2text/token.rb', line 229 def initialize(label, link, include_ws = false) @text = label.gsub(ESCAPE_CHAR, "\"") @link = link.gsub("'","%27").gsub("\"","%22").gsub("<", "%3C").gsub(">", "%3E") @include_ws = include_ws end |
Instance Attribute Details
#include_ws ⇒ Object
Returns the value of attribute include_ws.
227 228 229 |
# File 'lib/me2text/token.rb', line 227 def include_ws @include_ws end |
#link ⇒ Object
Returns the value of attribute link.
226 227 228 |
# File 'lib/me2text/token.rb', line 226 def link @link end |
Instance Method Details
#length(options = {}) ⇒ Object
273 274 275 |
# File 'lib/me2text/token.rb', line 273 def length( = {}) textize(@text,).length end |
#to_html(options = {}) ⇒ Object
261 262 263 264 265 266 267 |
# File 'lib/me2text/token.rb', line 261 def to_html( = {}) if [:open_new_window] "<a href='#{link}' target='_blank'>#{to_label(:html,)}</a>" else "<a href='#{link}'>#{to_label(:html,)}</a>" end end |
#to_label(format, options = {}) ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/me2text/token.rb', line 235 def to_label(format, = {}) = .merge({ :linklize => false }) result = if format == :html htmlize(@text, ) elsif format == :text textize(@text, ) else @text end if result.strip.length == 0 if format == :html result = htmlize(" " + link + " ",) elsif format == :text result = textize(" " + link + " " ,) else @text end end return result end |
#to_text(options = {}) ⇒ Object
269 270 271 |
# File 'lib/me2text/token.rb', line 269 def to_text( = {}) to_label(:text, ) end |
#truncate(nos, format, options = {}) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/me2text/token.rb', line 277 def truncate(nos, format, = {}) = { :ellipsis => "…" }.merge() val = self.to_label(format,) if (val.length - nos) <= 0 #빼면 아무것도 없다면.. ##이 링크는 버린다 [:ellipsis] else val = val.split(//u)[0...(val.length-nos) - 1] val << [:ellipsis] end @text= val [to_s(format,), length()] end |