Class: Troo::Decorators::Resource

Inherits:
Object
  • Object
show all
Includes:
Troo::DecoratorHelpers
Defined in:
lib/troo/decorators/resource.rb

Direct Known Subclasses

Member

Instance Method Summary collapse

Methods included from Troo::DecoratorHelpers

included

Constructor Details

#initialize(klass, options = {}) ⇒ Troo::Decorators::Resource

Parameters:

  • []
  • (Hash)


9
10
11
# File 'lib/troo/decorators/resource.rb', line 9

def initialize(klass, options = {})
  @klass, @options = klass, options
end

Instance Method Details

#as_viewString

Returns:

  • (String)


101
102
103
# File 'lib/troo/decorators/resource.rb', line 101

def as_view
  Template.parse(self, '/../views/' + type + '.erb')
end

#boardObject

Returns [].

Returns:



65
66
67
# File 'lib/troo/decorators/resource.rb', line 65

def board
  klass.board.decorator
end

#commentsString

Returns:

  • (String)


75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/troo/decorators/resource.rb', line 75

def comments
  if klass.comments.any? && klass.comments.size > 3
    msg = '(There are more comments, use: ' \
          "'troo show comments #{klass.short_id}' to view " \
          ' all comments.)'
    [decorated_recent_comments, msg].join("\n")
  elsif klass.comments.any?
    decorated_all_comments
  else
    'No comments have been left.'
  end
end

#dateString

Returns:

  • (String)


116
117
118
# File 'lib/troo/decorators/resource.rb', line 116

def date
  Time.parse(klass.date).strftime('%a, %b %d at %H:%M')
end

#defaultString, NilClass

Returns:

  • (String, NilClass)


55
56
57
# File 'lib/troo/decorators/resource.rb', line 55

def default
  klass.default? ? '*' : nil
end

#descriptionString

Returns:

  • (String)


48
49
50
51
52
# File 'lib/troo/decorators/resource.rb', line 48

def description
  return 'N/A' if klass.description.nil? ||
                  klass.description.empty?
  Troo::Formatter.wordwrap(klass.description)
end

#idObject

Returns [].

Returns:



43
44
45
# File 'lib/troo/decorators/resource.rb', line 43

def id
  (klass.type == :card) ? klass.short_id : klass.id
end

#last_activity_dateString

Returns:

  • (String)


94
95
96
97
98
# File 'lib/troo/decorators/resource.rb', line 94

def last_activity_date
  return 'N/A' unless klass.last_activity_date
  Time.parse(klass.last_activity_date)
      .strftime('%a, %b %d at %H:%M')
end

#listObject

Returns [].

Returns:



70
71
72
# File 'lib/troo/decorators/resource.rb', line 70

def list
  klass.list.decorator
end

#membersString

Returns:

  • (String)


89
90
91
# File 'lib/troo/decorators/resource.rb', line 89

def members
  Presenters::Member.new(klass).show
end

#nameString

Returns:

  • (String)


60
61
62
# File 'lib/troo/decorators/resource.rb', line 60

def name
  (klass.name && klass.name.chomp) || 'N/A'
end

#resource_idString

Returns:

  • (String)


33
34
35
36
37
38
39
40
# File 'lib/troo/decorators/resource.rb', line 33

def resource_id
  if klass.type == :card
    brackets(Troo::Formatter.highlight(
      Troo::Wordwrap.this(id), options))
  else
    brackets(id)
  end
end

#resource_titleString

Returns:

  • (String)


23
24
25
26
27
28
29
30
# File 'lib/troo/decorators/resource.rb', line 23

def resource_title
  if klass.type == :card
    Troo::Wordwrap.this(name, prune: true)
  else
    Troo::Formatter.highlight(
      Troo::Wordwrap.this(name, prune: true), options)
  end
end

#textString

Returns:

  • (String)


111
112
113
# File 'lib/troo/decorators/resource.rb', line 111

def text
  Troo::Formatter.wordwrap(klass.text)
end

#titleString

Returns:

  • (String)


14
15
16
17
18
19
20
# File 'lib/troo/decorators/resource.rb', line 14

def title
  [
    resource_id,
    resource_title,
    default
  ].compact.join(' ') + "\n"
end

#usernameString

Returns:

  • (String)


106
107
108
# File 'lib/troo/decorators/resource.rb', line 106

def username
  ['@', klass.member.username].join
end