Class: Command::List::NovelDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/command/list/novel_decorator.rb

Instance Method Summary collapse

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.options = parent.options
  self.parent = parent
end

Instance Method Details

#decorate_authorObject



50
51
52
# File 'lib/command/list/novel_decorator.rb', line 50

def decorate_author
  options["author"] ? novel["author"].escape : nil
end

#decorate_dateObject



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_idObject



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_kindObject



46
47
48
# File 'lib/command/list/novel_decorator.rb', line 46

def decorate_kind
  options["kind"] ? NOVEL_TYPE_LABEL[novel_type] : nil
end

#decorate_lineObject



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_author,
    decorate_site,
    decorate_title,
    decorate_url,
    decorate_tags
  ].compact.join(" | ")
end

#decorate_siteObject



54
55
56
# File 'lib/command/list/novel_decorator.rb', line 54

def decorate_site
  options["site"] ? novel["sitename"].escape : nil
end

#decorate_tagsObject



76
77
78
79
80
81
82
# File 'lib/command/list/novel_decorator.rb', line 76

def decorate_tags
  return nil unless options["tags"] || options["all-tags"]
  tags.empty? ? nil : tags.map { |tag|
    color = Tag.get_color(tag)
    "<bold><#{color}>#{tag.escape}</#{color}></bold>"
  }.join(",")
end

#decorate_titleObject



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 !options["kind"] && novel_type == 2
    type = " <bold><black>(#{NOVEL_TYPE_LABEL[novel_type]})</black></bold>"
  end
  the_end = "<bold><black>(完結)</black></bold>" if tags.include?("end")
  delete = "<bold><black>(削除)</black></bold>" if tags.include?("404")
  [
    novel["title"].escape,
    type,
    the_end,
    delete
  ].compact.join(" ")
end

#decorate_urlObject



72
73
74
# File 'lib/command/list/novel_decorator.rb', line 72

def decorate_url
  options["url"] ? novel["toc_url"].escape : nil
end