Class: Command::List::NovelDecorator
- Inherits:
-
Object
- Object
- Command::List::NovelDecorator
- Defined in:
- lib/command/list/novel_decorator.rb
Instance Method Summary collapse
- #decorate_author ⇒ Object
- #decorate_date ⇒ Object
- #decorate_id ⇒ Object
- #decorate_kind ⇒ Object
- #decorate_line ⇒ Object
- #decorate_site ⇒ Object
- #decorate_tags ⇒ Object
- #decorate_title ⇒ Object
- #decorate_url ⇒ Object
-
#initialize(novel, parent) ⇒ NovelDecorator
constructor
A new instance of NovelDecorator.
Constructor Details
#initialize(novel, parent) ⇒ NovelDecorator
Returns a new instance of NovelDecorator.
12 13 14 15 16 17 18 19 |
# File 'lib/command/list/novel_decorator.rb', line 12 def initialize(novel, parent) self.id = novel["id"] self.frozen = Narou.novel_frozen?(id) self.novel_type = novel["novel_type"].to_i self.novel = novel self. = parent. self.parent = parent end |
Instance Method Details
#decorate_author ⇒ Object
50 51 52 |
# File 'lib/command/list/novel_decorator.rb', line 50 def ["author"] ? novel["author"].escape : nil end |
#decorate_date ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/command/list/novel_decorator.rb', line 30 def decorate_date date = novel[parent.view_date_type].strftime("%y/%m/%d") new_arrivals_date = novel["new_arrivals_date"] last_update = novel["last_update"] if new_arrivals_date && new_arrivals_date >= last_update && new_arrivals_date + ANNOTATION_COLOR_TIME_LIMIT >= now # 新着表示色 "<bold><magenta>#{date}</magenta></bold>" elsif last_update + ANNOTATION_COLOR_TIME_LIMIT >= now # 更新だけあった色 "<bold><green>#{date}</green></bold>" else date end end |
#decorate_id ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/command/list/novel_decorator.rb', line 21 def decorate_id disp_id = ((frozen ? "*" : "") + id.to_s).rjust(4) if frozen disp_id.sub("*", "<bold><cyan>*</cyan></bold>") else disp_id end end |
#decorate_kind ⇒ Object
46 47 48 |
# File 'lib/command/list/novel_decorator.rb', line 46 def decorate_kind ["kind"] ? NOVEL_TYPE_LABEL[novel_type] : nil end |
#decorate_line ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/command/list/novel_decorator.rb', line 84 def decorate_line [ decorate_id, decorate_date, decorate_kind, , decorate_site, decorate_title, decorate_url, ].compact.join(" | ") end |
#decorate_site ⇒ Object
54 55 56 |
# File 'lib/command/list/novel_decorator.rb', line 54 def decorate_site ["site"] ? novel["sitename"].escape : nil end |
#decorate_tags ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/command/list/novel_decorator.rb', line 76 def return nil unless ["tags"] || ["all-tags"] .empty? ? nil : .map { |tag| color = Tag.get_color(tag) "<bold><#{color}>#{tag.escape}</#{color}></bold>" }.join(",") end |
#decorate_title ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/command/list/novel_decorator.rb', line 58 def decorate_title if !["kind"] && novel_type == 2 type = " <bold><black>(#{NOVEL_TYPE_LABEL[novel_type]})</black></bold>" end the_end = "<bold><black>(完結)</black></bold>" if .include?("end") delete = "<bold><black>(削除)</black></bold>" if .include?("404") [ novel["title"].escape, type, the_end, delete ].compact.join(" ") end |
#decorate_url ⇒ Object
72 73 74 |
# File 'lib/command/list/novel_decorator.rb', line 72 def decorate_url ["url"] ? novel["toc_url"].escape : nil end |