Class: Me2Text::Keyword
Constant Summary collapse
- KEYWORD_REGEX =
/(\[([^\[\]]+)\])/u
Constants inherited from Token
Token::ESCAPE_CHAR, Token::REGEX_ME2LINK, Token::REGEX_URL
Instance Attribute Summary collapse
-
#link ⇒ Object
Returns the value of attribute link.
Attributes inherited from Token
Instance Method Summary collapse
-
#initialize(keyword, options) ⇒ Keyword
constructor
A new instance of Keyword.
- #length(options = {}) ⇒ Object
- #to_html(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(keyword, options) ⇒ Keyword
Returns a new instance of Keyword.
301 302 303 304 305 306 307 308 309 |
# File 'lib/me2text/token.rb', line 301 def initialize(keyword, ) # keyword는 "[키워드]" 같은 형태 _keyword = keyword.to_s.strip.scan(KEYWORD_REGEX) _keyword = _keyword.flatten[1] raise ArgumentError.new("키워드가 없습니다.") if _keyword.nil? @text = _keyword.gsub(ESCAPE_CHAR, "\"") end |
Instance Attribute Details
#link ⇒ Object
Returns the value of attribute link.
299 300 301 |
# File 'lib/me2text/token.rb', line 299 def link @link end |
Instance Method Details
#length(options = {}) ⇒ Object
323 324 325 |
# File 'lib/me2text/token.rb', line 323 def length( = {}) textize(@text, ).length end |
#to_html(options = {}) ⇒ Object
311 312 313 314 315 316 317 |
# File 'lib/me2text/token.rb', line 311 def to_html( = {}) if [:keyword_handler] && [:keyword_handler].is_a?(Proc) [:keyword_handler].call(@text, ) else "[#{htmlize(@text, options)}]" end end |
#to_text(options = {}) ⇒ Object
319 320 321 |
# File 'lib/me2text/token.rb', line 319 def to_text( = {}) "[#{textize(@text, options)}]" end |
#truncate(nos, format, options = {}) ⇒ Object
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/me2text/token.rb', line 327 def truncate(nos, format, = {}) = { :ellipsis => "…" }.merge() val = self.to_text() 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 |