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.
11 12 13 14 15 16 17 18 |
# File 'lib/command/list/novel_decorator.rb', line 11 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
49 50 51 |
# File 'lib/command/list/novel_decorator.rb', line 49 def ["author"] ? novel["author"].escape : nil end |
#decorate_date ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/command/list/novel_decorator.rb', line 29 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
20 21 22 23 24 25 26 27 |
# File 'lib/command/list/novel_decorator.rb', line 20 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
45 46 47 |
# File 'lib/command/list/novel_decorator.rb', line 45 def decorate_kind ["kind"] ? NOVEL_TYPE_LABEL[novel_type] : nil end |
#decorate_line ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/command/list/novel_decorator.rb', line 83 def decorate_line [ decorate_id, decorate_date, decorate_kind, , decorate_site, decorate_title, decorate_url, ].compact.join(" | ") end |
#decorate_site ⇒ Object
53 54 55 |
# File 'lib/command/list/novel_decorator.rb', line 53 def decorate_site ["site"] ? novel["sitename"].escape : nil end |
#decorate_tags ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/command/list/novel_decorator.rb', line 75 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
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/command/list/novel_decorator.rb', line 57 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
71 72 73 |
# File 'lib/command/list/novel_decorator.rb', line 71 def decorate_url ["url"] ? novel["toc_url"].escape : nil end |